-
-
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
docs: revise documentation for best image practices #11792
Conversation
Add information about making priority, using rem, etc.
Add information about compression, priority, cumulative layout shift, and using rem.
|
Add information about compression, priority, cumulative layout shift, and using rem.
Add information about compression, priority, cumulative layout shift, and using rem.
Add information about compression, priority, cumulative layout shift, and using rem.
@benmccann When working with some SVG, I noticed if I put it in a component like I see often suggested, then the SVG nodes get parsed by Svelte and end up duplicated in the prerendered HTML as well as the JavaScript bundle. If you do For this reason I opted to link to a "stacked" SVG like so: <svg xmlns="http://www.w3.org/2000/svg">
<style>
svg { display: none }
svg:target { display: inline }
</style>
<svg id="key" viewBox="0 0 876 240">
<defs>
<linearGradient ... <img src="/svg/above-the-fold.svg#key" alt="" loading="eager" fetchpriority="high" /> This works. However this file is only 5kb after compression so I decided it might be best to inline it again, but to avoid having it duplicated in the JavaScript bundle, I put it inside the And linked to the symbols like so: <svg aria-hidden="true">
<use href="#key" />
</svg> Do you think an explanation like this would be worth adding to the best image practices documentation? Is there some other way to have svelte not duplicate the SVG in JS? |
I tend to think that we shouldn't document this for a couple of reasons. The first is that it probably only helps for images in your layout - if it's on a sub-page then you're including the image on the page without necessarily using it. The bigger issue in my mind though is that this doesn't seem like the ideal long-term fix. Instead, Svelte should figure out how to support something like partial hydration. See #1390 for a discussion of that. It's something we're thinking about, but won't get too soon as it's tricky to figure out what to do. I'll post some updated thoughts there shortly. |
@benmccann What about a |
I think there may have been a I'm not sure what you think about my suggestions above, but if you don't have any objections to them I could merge them into my PR. I did have one question about whether there are any references for more detailed info here: #11792 (comment) |
Here was my reply to (that you may have missed):
That website explains: https://web.dev/learn/design/responsive-images#preloading_hints
Furthermore, from MDN: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding
As we are discussing what is best for an above-the-fold high-priority image, this line seems pertinent:
However, there is other info there about |
Thanks. MDN says:
And web.dev says:
Given that it seems to have little impact I think I'll remove that part |
This PR adds information about compression, priority, cumulative layout shift, and using rem (#11791).
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. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits