-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sizes
needs to be on the source
-tag
#7997
Conversation
|
@PatrickG is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
Thank you. The sizes themselves were based on an old layout, so I've updated those. For the life of me though, I can't get the browser to actually load the 960px-wide image. It loads the 1440px-wide one every time, even on tiny screens. Any idea what's going on? |
Could it be related to retina screens? This would cause the browser to load the higher res images. |
That was my thought too, but I tried crazy breakpoints like 3000px and still nothing :/ |
{#each Object.entries(background.sources) as [format, images]} | ||
<source | ||
sizes="(min-width: 768) 1440px, 960px" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- sizes="(min-width: 768) 1440px, 960px"
+ sizes="(min-width: 768px) 1440px, 960px"
After adding the missing px
, I've observed that Chrome, Safari, and Firefox all have different behaviours for this (tested on MacOS).
1. Firefox is the only browser that correctly implements this.
- Respects the
sizes
attribute. - Changes the image when resizing the window.
2. Safari.
- Respects the
sizes
attribute. - Does not change the image when resizing the window (it only loads the correct image on initial page load).
3. Chrome
- Does not respect the
sizes
attribute (always loads the largest image). - Removing the
sizes
attribute enablessrcset
to work correctly (loads the next largest image on resize).
Would be great if someone else could verify these behaviours too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not test on Safari, but it seems Firefox behaves similarly to Chrome for me. It always loads the largest if the sizes
attribute is present.
Removing the sizes attribute enables srcset to work correctly (loads the next largest image on resize).
I would not say "correctly", but at least something happens.
Without the sizes
attribute, Chrome switches to the large image when the screen width is
>= 961px
(DPR: 1.0)>= 588px
(DPR: 2.0)>= 392px
(DPR: 3.0)
while Firefox switches to the large image when the screen width is
>= 961px
(DPR: 1.0)>= 481px
(DPR: 2.0)>= 321px
(DPR: 3.0)
with this import ./svelte-kit-machine.webp?w=960;1440&format=avif;webp;png&picture
|
Thank you @PatrickG and @s3812497 for the thorough investigation — agree that removing I shouldn't complain — I'm old enough to remember IE6 — but the web platform continues to be a cruel prank. And they wonder why people turn to JavaScript instead of uSinG tHe PlAtfOrM |
The
sizes
attribute needs to be on thesource
-tag.See source vs picture attributes.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0