Skip to content

Commit 280d61d

Browse files
committed
fix: use renderBlockingStatus to avoid false positives in Critical CSS Detection
Fixes #64 The media/onload deferral pattern (media="print" onload="this.media='all'") was incorrectly flagged as render-blocking. By the time the snippet runs, the onload handler has already mutated the media attribute to "all", making the DOM-based check unreliable. Now uses PerformanceResourceTiming.renderBlockingStatus (Chrome 107+) as the primary signal — it reflects actual render-blocking during page load. The DOM heuristic is kept as a fallback with a comment noting its limitation.
1 parent 98874e2 commit 280d61d

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

.claude/skills/webperf-loading/scripts/Critical-CSS-Detection.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

skills/webperf-loading/scripts/Critical-CSS-Detection.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snippets/Loading/Critical-CSS-Detection.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,25 @@
2424
const href = link.href;
2525
const media = link.getAttribute("media") || "all";
2626

27-
// A stylesheet is render-blocking when it applies to screen without deferral
28-
const isRenderBlocking =
29-
media === "all" ||
30-
media === "" ||
31-
media === "screen" ||
32-
(media.toLowerCase().includes("screen") &&
33-
!media.toLowerCase().includes("print"));
34-
3527
const perfEntry = perfEntries.find((e) => e.name === href);
28+
29+
// Prefer browser-reported render-blocking status (PerformanceResourceTiming API,
30+
// Chrome 107+). This correctly handles the media="print" onload="this.media='all'"
31+
// deferral pattern — by page load time the media attribute has already changed to
32+
// "all", so a DOM-only check would produce false positives.
33+
let isRenderBlocking;
34+
if (perfEntry && perfEntry.renderBlockingStatus !== undefined) {
35+
isRenderBlocking = perfEntry.renderBlockingStatus === "blocking";
36+
} else {
37+
// Fallback for browsers without renderBlockingStatus support.
38+
// Note: may produce false positives when the media/onload deferral pattern is used.
39+
isRenderBlocking =
40+
media === "all" ||
41+
media === "" ||
42+
media === "screen" ||
43+
(media.toLowerCase().includes("screen") &&
44+
!media.toLowerCase().includes("print"));
45+
}
3646
const transferSize = perfEntry ? perfEntry.transferSize : 0;
3747
const decodedSize = perfEntry ? perfEntry.decodedBodySize : 0;
3848

0 commit comments

Comments
 (0)