Skip to content

perf/total-byte-weight: loading=lazy images counted into the initial page weight #1252

Closed

Description

@deniskern

Summary

perf/total-byte-weight adds every loading="lazy" image to the page weight. Lazy images outside the viewport are not fetched on load, so the reported page weight is several times what a visitor downloads.

Real case: a Shopify product page reported at 5.4 MB; a real browser loads about 1.3 MB after 5 s (the rest are lazy gallery/recommendation images).

Minimal repro

<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Image weight rule repro page for squirrel audits</title></head><body>
<main><h1>lazy</h1><p>Text.</p>
``&lt;img src="lazy1.jpg" loading="lazy" width="400" height="300" alt="Item 1"&gt;``
````&lt;img src="lazy2.jpg" loading="lazy" width="400" height="300" alt="Item 2"&gt;````
`````&lt;img src="lazy3.jpg" loading="lazy" width="400" height="300" alt="Item 3"&gt;`````
``````&lt;img src="lazy4.jpg" loading="lazy" width="400" height="300" alt="Item 4"&gt;``````
```````&lt;img src="lazy5.jpg" loading="lazy" width="400" height="300" alt="Item 5"&gt;```````
````````&lt;img src="lazy6.jpg" loading="lazy" width="400" height="300" alt="Item 6"&gt;````````
</main></body></html>

Each lazyN.jpg = 400 KB.

squirrel audit http://localhost:8766/lazy.html --http -f json -o out.json

Actual

{"ruleId":"perf/total-byte-weight","status":"warn","message":"Heaviest page: http://localhost:8766/lazy.html 2345KB (1 over 1600KB, 0 over 5000KB) (heavy page)","details":{"images":"2344KB"}}

Expected

Initial page weight excludes lazy images the rule itself considers below the fold (perf/lazy-above-fold treats only the first three as above-fold here), or reports them separately (e.g. lazyImages in details) instead of in the heaviest-page total. Related: srcset candidates should count as the selected candidate only (see the image-file-size issue).

Version

squirrel 0.0.138 (macOS arm64), --http mode.

Triage

Plausible on current main, not reproduced end to end. packages/rules/src/performance/total-byte-weight.ts sums per-page buckets (html, css, js, images, fonts) from ctx.site.resourceSizes and the page's external records without regard to loading="lazy", so below-the-fold lazy images are counted in the initial weight. Related to #1251 (candidate selection) and to the above-fold split in #1250.

Acceptance Criteria

  • The repro page above no longer reports its six lazy images in the initial page weight total.
    amended 2026-11-02: on the repro page, the lazy images beyond the first three content images are not in the initial page weight and are reported as lazyImages; the first three content images count as in the initial viewport.
  • Lazy images the rule treats as below the fold are reported separately (for example lazyImages in details) or omitted from the heaviest-page total.
  • Lazy images that are above the fold, and eager images, still count toward the total.
  • A regression test covers a page with lazy and eager images, and the rule docs say how lazy images are counted.

Activity

  1. added
    bug
    size: M
    rules
    on Oct 29, 2026
  2. added theissue type on Oct 29, 2026
  3. nc9 commented on Oct 30, 2026

    @nc9
    Contributor

    Maintainer-decision needed (from PR #1296): the acceptance criteria point two ways. AC1 says the repro's six lazy images no longer count toward the initial weight; AC3 says lazy images above the fold still count. The repro's first three images sit inside the three-image above-the-fold budget the rules already share, so the PR keeps those three counted (1,200 KB) and reports the other three as lazyImages in the details. Proposal: keep that reading (it matches browsers, which load lazy images that are in the viewport). If instead every loading="lazy" image should be excluded, say so and AC3 changes; it is a one-line change in the asset collector.

  4. nc9 commented on Oct 30, 2026

    @nc9
    Contributor

    Checked against main (23a34c1, v0.0.144). Ticked what holds. Open: criterion 1 says the six lazy images of the repro page no longer count, but the implementation keeps the first three content images (the initial-viewport budget from #1250) counted, so 1200 KB of lazy images still count; the rest are reported as lazyImages. The maintainer-decision comment on this thread has no recorded answer. Restate criterion 1 (it conflicts with criterion 3 as written) or change the budget.

    nik

  5. nc9 commented on Nov 2, 2026

    @nc9
    Contributor

    Verified on main (e86767ff). e54a36d7 is an ancestor of main and added packages/rules/tests/total-byte-weight-lazy-1252.test.ts. Its first test builds the repro shape (six 400 KB lazy images below the fold): status pass, page weight 2 KB, lazyImages reported as 2400KB, no images entry. The file passes 4/4 locally (bun 1.4.0). All four boxes ticked, closing.

    nik

  6. nc9 commented on Nov 2, 2026

    @nc9
    Contributor

    Correction to the close comment above: it claimed more than the unit test shows. The test passes because it marks all six images as deferred by hand, which bypasses the engine; in the engine the first three content images count as in the initial viewport and stay in the total, as docs/rules/perf/total-byte-weight.mdx says. Measured with the real CLI (squirrel audit --http) on a loopback page with six loading="lazy" 400x300 images of 600 KB each: warn at 1801 KB, with images and lazyImages both 1800KB, i.e. three images counted. With 400 KB images the same page passes (three counted images are 1200 KB, under the 1600 KB line), so the original 2345 KB warn is resolved for the issue's 400 KB repro. Criterion 1 is amended to say that (original text kept visible); criteria 2 to 4 are met (total-byte-weight-lazy-1252.test.ts passes, 4 tests; image-load-occurrences-1250.test.ts passes, 9). The issue stays closed.

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions