johannschopplich / unlazy

🪧 Universal lazy loading library for placeholder images leveraging native browser APIs

Home Page:https://unlazy.byjohann.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect loading behaviour in Chrome web browser

felixranesberger opened this issue · comments

Reproduction

I cant share the link to the customer, but it happens on two webpages in the menu.

Describe the bug

Chrome preloads menu images on a customer webpage of mine, even if they are hidden initially.
Hidden images have no width and height and the auto-sizes calculation skips and sets no sizes attribute.
The srcset injection still occurs and replaces the data-srcset with srcset.
Without a sizes attribute set, the image will fallback to the default 100vw value and will load the largest image possible (with a large screen).

The images are loaded after the CSS is loaded, so the image should already hidden by then.
Only Chrome has this issue, Firefox behaves correctly.

Order of events

  1. HTML is loaded
  2. CSS is loaded main-[hash].css
  3. Hidden images are loaded by Chrome (not Firefox)
  4. Images have no size => sizes attribution fails => no sizes attribute set
  5. Srcset is still injected
  6. Without sizes attribute, browser fallbacks to 100vw.
  7. Loads large mega-navi.jpg (example - happens with other images in the menu too)
Screenshot 2023-11-07 at 12 19 41

Additional context

No response

Logs

No response

Do you have an idea, why this would occur?

@felixranesberger What was the solution to your problem?

The original issue of chrome preloading the images, even if they're not visible was somehow fixed.
I updated from v0.10.0 to v.0.10.2, but not sure if this resolved the issue.

Currently the auto sizes does not work, but I'm creating a pull request to fix the issue.

I closed the GitHub issue to cause no confusion 👍