Repository navigation
Conversation
… srcset candidate, leave lazy images out of page weight #1250 #1251 #1252 Signed-off-by: Nik Cubrilovic <[email protected]>
…es, keep own-host src when the candidate is off-origin #1251 #1252 Signed-off-by: Nik Cubrilovic <[email protected]>
This was referenced Oct 30, 2026
Contributor
Author
|
Landed in v0.0.143 as nik |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1250
Fixes #1251
Fixes #1252
What changed
One shared helper,
packages/utils/src/image-loading.ts, answers "which image file does a browser download for this<img>" and "is it in the initial viewport". It reads attribute strings only, with fixed reference constants (1280 px viewport, 2x density, a budget of 3 content images, icon = declared width and height under 20,000 square pixels), and is bounded against hostilesrcsetandsizesvalues.images/offscreen-lazy: the above-the-fold budget is counted in content images. Icon-sized images (both dimensions declared) neither fill it nor count as below the fold until it is full. Undeclared images count as content, so existing behaviour holds for them.images/image-file-size: the audit selects thesrcsetcandidate at the reference viewport and density (largest when none covers it;srcwithoutsrcset; an<img>inside<picture>keeps itssrc). The collector measures the selected candidate too and marks a file that is only an<img src>behind asrcsetasfallbackOnly, which the rule skips. The fallback is still fetched, becauseimages/responsive-sizepairs each<img>with itssrc.perf/total-byte-weight: lazy images below the initial viewport (deferredPagesper resource) are left out of a page's weight and reported aslazyImagesin the details;fallbackOnlyfiles are not counted. Eager images and lazy images in the initial viewport still count.ImageDatagains optionalsrcset,sizes,loading,inPicture(parser);ResourceSizeDatagains optionalfallbackOnly,deferredPages(core-contracts), set only when true so existing records are unchanged; the asset collector gets two optional maps (imagesSelected,imagesEager).perf/lazy-above-foldnow reads the shared budget constant (no behaviour change).perf/lazy-above-foldkeeps its own hidden, carousel and footer exclusions (different question),images/lazy-loadingonly counts,shared/lcp-candidateand thesrcset,picture-element,modern-formatrules read srcset for their own purposes; none of them select the loaded file, so none changed.perRuleTallychange (golden pins did not move).One tension in the issues, worth a look
#1252 AC1 says the repro's six lazy images no longer count, AC3 says lazy images above the fold still count. The repro's first three images are in the 3-image budget, so they still count (1,200 KB) and the other three (1,200 KB) move to
lazyImages. If maintainers want everyloading="lazy"image excluded, that is a one-line change in the collector, but it would contradict AC3.Tests (failing first)
utils/tests/image-loading.test.ts,rules/tests/offscreen-lazy-1250.test.ts,rules/tests/image-file-size-srcset-1251.test.ts,rules/tests/total-byte-weight-lazy-1252.test.ts,audit-engine/tests/image-load-occurrences-1250.test.ts(42 tests). With the three rule files reverted, 8 of the rule tests fail; restored, all pass.lazy-above-fold,perf-total-byte-weight-per-page,rule-verdict-scope,template-verdict-inputs,template-verdict-page-independence,docs-rule-pages,docs-category-table,streaming-rules-canonical-golden,page-rule-site-context,broken-resources-fixture,offline-own-site-819, parsernoscript-resources;make validateindocs/; tsgo on utils, parser, core-contracts, rules, audit-engine;test-suites.ts --check.scripts/test-suites.ts --run rulessuite, an end-to-endsquirrel auditof the issue pages, a real-site smoke test. Local Bun is not the pinned 1.4.4.Docs:
docs/rules/images/offscreen-lazy.mdx,docs/rules/images/image-file-size.mdx,docs/rules/perf/total-byte-weight.mdx. Skill: none.Review round 1 (head ede338d)
sizesparsing now reads parentheses as balanced groups: the source size is the trailing length or function, the media condition is what precedes it, so(min-width: 750px) calc((100vw - 130px) / 2),(max-width: 600px) calc(100vw - 20px), 400pxand(min-width: 40em) 300px, 100vwgive widths (575, 400, 300) instead of falling to the largest file.calc()supports px, vw, em, rem with + - * / and parentheses; an entry that cannot be read (min(),clamp(), unknown media) is skipped and the next one tried. Tests with Dawn-style sizes and the three cases above.deferredPagesis capped in the published report likesourcePages(capResourceSizes), tested.srcmeasured and counted (it used to becomefallbackOnlywith nothing measured). Tested.src(bounded by the existing resource-check budget);fallbackOnlyanddeferredPageslive only in the in-memory run (and the published report);saveResourceSizesand a report reconstructed from storage do not keep them, so a re-rendered stored report counts every image as before.