Skip to content

fix(rules): module scripts are not blocking in perf/inp-hints and perf/render-blocking (#424) - #428

Merged
nc9 merged 1 commit into
mainfrom
fix/module-scripts-not-blocking
Oct 1, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/module-scripts-not-blocking

Conversation

@nc9

@nc9 nc9 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #424.

perf/inp-hints and perf/render-blocking counted <script type="module" src> as blocking. Module scripts are deferred by spec, so a page full of them got "6 blocking scripts" and "7 render-blocking resources" for nothing.

What changed

  • New scriptLoading() in packages/rules/src/performance/cwv.ts classifies each <script src> the way the HTML Standard's "prepare the script element" steps do:
    • classic (no type, empty type, or a JavaScript MIME type; language as the fallback): async, defer, or blocking
    • type="module" (case and ASCII whitespace insensitive): deferred, or async with async; defer and nomodule do nothing
    • a classic script with nomodule, or any other type (text/plain consent gates, text/partytown, data blocks): never run by a modern browser, so never blocking
  • perf/inp-hints and perf/render-blocking read it through the shared CWV hints. perf/critical-request-chains uses the same helper instead of its own selector, so the three rules agree, and it no longer lists a <script src=""> as JS: unknown.
  • The third-party count in perf/inp-hints is unchanged: a consent-gated text/plain tag usually runs once the banner is accepted.
  • Docs for the three rules say what counts and what does not.

Result on the reporter's page

Run from source against the repro in #424: inp-blocking-scripts passes (0 blocking, 6 deferred), render-blocking lists only /style.css, inp-third-party still reports the 6 tags.

Tests

  • packages/rules/tests/script-loading.test.ts (new): the classification table, including whitespace, case, language, MIME parameters and empty src, plus the three rules on module, classic, nomodule and text/plain pages. 20 pass with cwv-reuse.test.ts.
  • tsgo --noEmit in packages/rules: clean. tangly check --strict in docs/: all checks passed.

Thanks to @deniskern for the clear report and the repro page.

…f/render-blocking #424

Classify each <script src> the way the HTML Standard does: type=module defers by default (async with async), and nomodule or non-JavaScript types never run in a modern browser. perf/critical-request-chains uses the same helper so the three rules agree.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/module-scripts-not-blocking branch from 0925a36 to 4d7328e Compare October 1, 2026 18:52
@nc9
nc9 merged commit 2a6cc0f into main Oct 1, 2026
14 checks passed
@nc9
nc9 deleted the fix/module-scripts-not-blocking branch October 1, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf/inp-hints and perf/render-blocking count type="module" scripts as blocking

1 participant