webperf-snippets 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +139 -0
  2. package/package.json +54 -0
  3. package/snippets/CoreWebVitals/CLS.js +88 -0
  4. package/snippets/CoreWebVitals/INP.js +432 -0
  5. package/snippets/CoreWebVitals/LCP-Image-Entropy.js +198 -0
  6. package/snippets/CoreWebVitals/LCP-Subparts.js +286 -0
  7. package/snippets/CoreWebVitals/LCP-Trail.js +184 -0
  8. package/snippets/CoreWebVitals/LCP-Video-Candidate.js +228 -0
  9. package/snippets/CoreWebVitals/LCP.js +135 -0
  10. package/snippets/CoreWebVitals/WORKFLOWS.md +203 -0
  11. package/snippets/DevTools-Overrides/Fetch-XHR-Timeline-inject.js +73 -0
  12. package/snippets/DevTools-Overrides/Fetch-XHR-Timeline-read.js +191 -0
  13. package/snippets/Interaction/Forced-Synchronous-Layout.js +286 -0
  14. package/snippets/Interaction/Input-Latency-Breakdown.js +199 -0
  15. package/snippets/Interaction/Interactions.js +220 -0
  16. package/snippets/Interaction/Layout-Shift-Loading-and-Interaction.js +266 -0
  17. package/snippets/Interaction/Long-Animation-Frames-Helpers.js +397 -0
  18. package/snippets/Interaction/Long-Animation-Frames-Script-Attribution.js +137 -0
  19. package/snippets/Interaction/Long-Animation-Frames.js +298 -0
  20. package/snippets/Interaction/LongTask.js +203 -0
  21. package/snippets/Interaction/Scroll-Performance.js +359 -0
  22. package/snippets/Interaction/WORKFLOWS.md +205 -0
  23. package/snippets/Loading/Back-Forward-Cache.js +473 -0
  24. package/snippets/Loading/CSS-Media-Queries-Analysis.js +512 -0
  25. package/snippets/Loading/Cache-Strategy-Analysis.js +808 -0
  26. package/snippets/Loading/Client-Side-Redirect-Detection.js +337 -0
  27. package/snippets/Loading/Content-Visibility.js +352 -0
  28. package/snippets/Loading/Critical-CSS-Detection.js +329 -0
  29. package/snippets/Loading/Event-Processing-Time.js +179 -0
  30. package/snippets/Loading/FCP.js +101 -0
  31. package/snippets/Loading/Find-Above-The-Fold-Lazy-Loaded-Images.js +264 -0
  32. package/snippets/Loading/Find-Images-With-Lazy-and-Fetchpriority.js +155 -0
  33. package/snippets/Loading/Find-non-Lazy-Loaded-Images-outside-of-the-viewport.js +300 -0
  34. package/snippets/Loading/Find-render-blocking-resources.js +161 -0
  35. package/snippets/Loading/First-And-Third-Party-Script-Info.js +269 -0
  36. package/snippets/Loading/First-And-Third-Party-Script-Timings.js +295 -0
  37. package/snippets/Loading/Fonts-Preloaded-Loaded-and-used-above-the-fold.js +317 -0
  38. package/snippets/Loading/Inline-CSS-Info-and-Size.js +234 -0
  39. package/snippets/Loading/Inline-Script-Info-and-Size.js +323 -0
  40. package/snippets/Loading/JS-Execution-Time-Breakdown.js +336 -0
  41. package/snippets/Loading/Prefetch-Resource-Validation.js +456 -0
  42. package/snippets/Loading/Priority-Hints-Audit.js +336 -0
  43. package/snippets/Loading/Resource-Hints-Validation.js +503 -0
  44. package/snippets/Loading/Resource-Hints.js +400 -0
  45. package/snippets/Loading/SSR-Hydration-Data-Analysis.js +364 -0
  46. package/snippets/Loading/Script-Loading.js +332 -0
  47. package/snippets/Loading/Service-Worker-Analysis.js +192 -0
  48. package/snippets/Loading/TTFB-Resources.js +115 -0
  49. package/snippets/Loading/TTFB-Sub-Parts.js +117 -0
  50. package/snippets/Loading/TTFB.js +37 -0
  51. package/snippets/Loading/Validate-Preload-Async-Defer-Scripts.js +394 -0
  52. package/snippets/Loading/WORKFLOWS.md +163 -0
  53. package/snippets/Media/Image-Element-Audit.js +350 -0
  54. package/snippets/Media/SVG-Embedded-Bitmap-Analysis.js +225 -0
  55. package/snippets/Media/Video-Element-Audit.js +282 -0
  56. package/snippets/Media/WORKFLOWS.md +190 -0
  57. package/snippets/README.md +98 -0
  58. package/snippets/Resources/Network-Bandwidth-Connection-Quality.js +103 -0
  59. package/snippets/Resources/WORKFLOWS.md +173 -0
  60. package/src/bin.js +229 -0
  61. package/src/decision-tree.js +19 -0
  62. package/src/load-snippet.js +23 -0
  63. package/src/reporters/human.js +179 -0
  64. package/src/reporters/json.js +3 -0
  65. package/src/runner.js +61 -0
  66. package/src/workflows/audit.js +21 -0
  67. package/src/workflows/cwv.js +10 -0
@@ -0,0 +1,359 @@
1
+ // Scroll Performance Analysis
2
+ // https://webperf-snippets.nucliweb.net
3
+
4
+ (() => {
5
+ const formatMs = (ms) => `${ms.toFixed(1)}ms`;
6
+ const formatFps = (fps) => `${fps.toFixed(0)} fps`;
7
+
8
+ const TARGET_FRAME_MS = 1000 / 60; // ~16.67ms at 60fps
9
+ const DROP_THRESHOLD_MS = TARGET_FRAME_MS * 1.5; // ~25ms = below 40fps
10
+
11
+ const RATING = {
12
+ good: { icon: "🟢", color: "#0CCE6A", label: "Good" },
13
+ "needs-improvement": { icon: "🟡", color: "#FFA400", label: "Needs Improvement" },
14
+ poor: { icon: "🔴", color: "#FF4E42", label: "Poor" },
15
+ };
16
+
17
+ const fpsRating = (fps) =>
18
+ fps >= 55 ? "good" : fps >= 40 ? "needs-improvement" : "poor";
19
+
20
+ // ─── 1. PASSIVE EVENT LISTENER DETECTION ────────────────────────────────────
21
+ // Detects scroll/touch listeners registered without { passive: true }.
22
+ // Non-passive listeners delay scroll by forcing the browser to wait for JS.
23
+
24
+ const nonPassiveListeners = [];
25
+ const SCROLL_EVENT_TYPES = new Set([
26
+ "scroll", "wheel", "touchstart", "touchmove", "touchend",
27
+ ]);
28
+
29
+ const _origAddEventListener = EventTarget.prototype.addEventListener;
30
+ EventTarget.prototype.addEventListener = function (type, listener, options) {
31
+ if (SCROLL_EVENT_TYPES.has(type)) {
32
+ const isPassive =
33
+ options === true
34
+ ? false // old-style capture boolean, not passive
35
+ : typeof options === "object" && options !== null
36
+ ? options.passive === true
37
+ : false;
38
+
39
+ if (!isPassive) {
40
+ const entry = {
41
+ type,
42
+ element: this.tagName || this.constructor?.name || "unknown",
43
+ id: this.id || "",
44
+ passive: false,
45
+ };
46
+ nonPassiveListeners.push(entry);
47
+ console.warn(
48
+ `%c⚠️ Non-passive "${type}" listener on <${entry.element}${
49
+ entry.id ? `#${entry.id}` : ""
50
+ }>`,
51
+ "color: #FFA400; font-weight: bold;",
52
+ this
53
+ );
54
+ console.warn(
55
+ " Fix: add { passive: true } to improve scroll performance."
56
+ );
57
+ }
58
+ }
59
+ return _origAddEventListener.call(this, type, listener, options);
60
+ };
61
+
62
+ // ─── 2. SCROLL FPS MEASUREMENT ──────────────────────────────────────────────
63
+ // Tracks requestAnimationFrame timing during active scroll sessions.
64
+
65
+ const sessions = [];
66
+ let currentSession = null;
67
+ let rafId = null;
68
+ let lastFrameTime = null;
69
+ let endTimer = null;
70
+
71
+ const trackFrame = (now) => {
72
+ if (!currentSession) return;
73
+ if (lastFrameTime !== null) {
74
+ const frameTime = now - lastFrameTime;
75
+ currentSession.frames.push(frameTime);
76
+ if (frameTime > DROP_THRESHOLD_MS) currentSession.drops++;
77
+ }
78
+ lastFrameTime = now;
79
+ rafId = requestAnimationFrame(trackFrame);
80
+ };
81
+
82
+ const endSession = () => {
83
+ if (!currentSession) return;
84
+ cancelAnimationFrame(rafId);
85
+
86
+ const { frames, drops } = currentSession;
87
+ if (frames.length < 2) {
88
+ currentSession = null;
89
+ return;
90
+ }
91
+
92
+ const avgFrameTime = frames.reduce((a, b) => a + b, 0) / frames.length;
93
+ const avgFps = 1000 / avgFrameTime;
94
+ const minFps = 1000 / Math.max(...frames);
95
+ const dropRate = (drops / frames.length) * 100;
96
+ const rating = fpsRating(avgFps);
97
+ const r = RATING[rating];
98
+
99
+ const session = {
100
+ avgFps,
101
+ minFps,
102
+ frames: frames.length,
103
+ drops,
104
+ dropRate,
105
+ rating,
106
+ };
107
+ sessions.push(session);
108
+
109
+ console.groupCollapsed(
110
+ `%c${r.icon} Scroll: avg ${formatFps(avgFps)} — ${frames.length} frames, ${drops} drop(s)`,
111
+ `font-weight: bold; color: ${r.color};`
112
+ );
113
+ console.table([
114
+ {
115
+ "Avg FPS": formatFps(avgFps),
116
+ "Min FPS": formatFps(minFps),
117
+ "Frames": frames.length,
118
+ "Drops": drops,
119
+ "Drop Rate": `${dropRate.toFixed(1)}%`,
120
+ "Rating": r.label,
121
+ },
122
+ ]);
123
+ if (drops > 0) {
124
+ const worstMs = Math.max(...frames);
125
+ console.log(
126
+ ` Worst frame: ${formatMs(worstMs)} (target: ${formatMs(TARGET_FRAME_MS)})`
127
+ );
128
+ }
129
+ console.groupEnd();
130
+
131
+ currentSession = null;
132
+ lastFrameTime = null;
133
+ };
134
+
135
+ window.addEventListener(
136
+ "scroll",
137
+ () => {
138
+ if (!currentSession) {
139
+ currentSession = { frames: [], drops: 0 };
140
+ lastFrameTime = null;
141
+ rafId = requestAnimationFrame(trackFrame);
142
+ }
143
+ clearTimeout(endTimer);
144
+ endTimer = setTimeout(endSession, 200);
145
+ },
146
+ { passive: true }
147
+ );
148
+
149
+ // ─── 3. CSS SCROLL AUDIT ────────────────────────────────────────────────────
150
+ // Checks CSS properties that affect scroll compositing and performance.
151
+
152
+ const auditScrollCSS = () => {
153
+ const results = {
154
+ smoothScrollElements: [],
155
+ willChangeElements: [],
156
+ contentVisibilityElements: [],
157
+ overscrollElements: [],
158
+ };
159
+
160
+ document.querySelectorAll("*").forEach((el) => {
161
+ const cs = getComputedStyle(el);
162
+ const label =
163
+ el.tagName.toLowerCase() +
164
+ (el.id ? `#${el.id}` : el.className
165
+ ? `.${String(el.className).trim().split(/\s+/)[0]}`
166
+ : "");
167
+
168
+ if (cs.scrollBehavior === "smooth") {
169
+ results.smoothScrollElements.push(label);
170
+ }
171
+ if (cs.willChange && cs.willChange !== "auto") {
172
+ results.willChangeElements.push({ element: label, value: cs.willChange });
173
+ }
174
+ if (cs.contentVisibility && cs.contentVisibility !== "visible") {
175
+ results.contentVisibilityElements.push({
176
+ element: label,
177
+ value: cs.contentVisibility,
178
+ });
179
+ }
180
+ if (cs.overscrollBehavior && cs.overscrollBehavior !== "auto") {
181
+ results.overscrollElements.push({
182
+ element: label,
183
+ value: cs.overscrollBehavior,
184
+ });
185
+ }
186
+ });
187
+
188
+ return results;
189
+ };
190
+
191
+ // ─── 4. SUMMARY ─────────────────────────────────────────────────────────────
192
+
193
+ window.getScrollSummary = () => {
194
+ console.group(
195
+ "%c📜 Scroll Performance Summary",
196
+ "font-weight: bold; font-size: 14px;"
197
+ );
198
+
199
+ // — Session stats
200
+ if (sessions.length === 0) {
201
+ console.log(" No scroll sessions recorded yet. Scroll the page first.");
202
+ } else {
203
+ const allFps = sessions.map((s) => s.avgFps);
204
+ const overallAvg = allFps.reduce((a, b) => a + b, 0) / allFps.length;
205
+ const worstAvg = Math.min(...allFps);
206
+ const totalDrops = sessions.reduce((a, s) => a + s.drops, 0);
207
+
208
+ console.log("%cScroll Sessions:", "font-weight: bold;");
209
+ console.table(
210
+ sessions.map((s, i) => ({
211
+ "#": i + 1,
212
+ "Avg FPS": formatFps(s.avgFps),
213
+ "Min FPS": formatFps(s.minFps),
214
+ "Drops": s.drops,
215
+ "Drop Rate": `${s.dropRate.toFixed(1)}%`,
216
+ "Rating": RATING[s.rating].icon + " " + RATING[s.rating].label,
217
+ }))
218
+ );
219
+ console.log(` Overall avg FPS: ${formatFps(overallAvg)}`);
220
+ console.log(` Worst session avg: ${formatFps(worstAvg)}`);
221
+ console.log(` Total frame drops: ${totalDrops}`);
222
+ }
223
+
224
+ // — Passive listeners
225
+ console.log("");
226
+ console.log("%cPassive Event Listeners:", "font-weight: bold;");
227
+ if (nonPassiveListeners.length === 0) {
228
+ console.log(
229
+ " ✅ No non-passive scroll listeners detected since snippet loaded."
230
+ );
231
+ } else {
232
+ console.log(
233
+ ` ❌ ${nonPassiveListeners.length} non-passive listener(s) found:`
234
+ );
235
+ console.table(nonPassiveListeners);
236
+ console.log(
237
+ " Fix: addEventListener('scroll', fn, { passive: true })"
238
+ );
239
+ }
240
+
241
+ // — CSS audit
242
+ console.log("");
243
+ console.log("%cCSS Scroll Audit:", "font-weight: bold;");
244
+ const css = auditScrollCSS();
245
+
246
+ if (css.contentVisibilityElements.length > 0) {
247
+ console.log(
248
+ ` ✅ content-visibility on ${css.contentVisibilityElements.length} element(s) — reduces off-screen layout cost.`
249
+ );
250
+ } else {
251
+ console.log(
252
+ " ℹ️ content-visibility not used — consider it for long pages."
253
+ );
254
+ }
255
+
256
+ if (css.smoothScrollElements.length > 0) {
257
+ console.log(
258
+ ` ℹ️ scroll-behavior: smooth on ${css.smoothScrollElements.length} element(s).`
259
+ );
260
+ console.log(
261
+ " Smooth scroll can cause jank if driven by JS instead of CSS."
262
+ );
263
+ }
264
+
265
+ if (css.willChangeElements.length > 0) {
266
+ console.log(
267
+ ` ⚠️ will-change set on ${css.willChangeElements.length} element(s):`
268
+ );
269
+ console.table(css.willChangeElements);
270
+ console.log(
271
+ " will-change creates compositor layers — use sparingly to avoid memory overhead."
272
+ );
273
+ }
274
+
275
+ if (css.overscrollElements.length > 0) {
276
+ console.log(
277
+ ` ℹ️ overscroll-behavior set on ${css.overscrollElements.length} element(s):`
278
+ );
279
+ console.table(css.overscrollElements);
280
+ }
281
+
282
+ // — Recommendations
283
+ const hasJank = sessions.some((s) => s.rating !== "good");
284
+ const hasNonPassive = nonPassiveListeners.length > 0;
285
+
286
+ if (hasJank || hasNonPassive) {
287
+ console.log("");
288
+ console.log(
289
+ "%c💡 Recommendations:",
290
+ "font-weight: bold; color: #3b82f6;"
291
+ );
292
+ if (hasNonPassive) {
293
+ console.log(
294
+ " • Add { passive: true } to all scroll/touch event listeners"
295
+ );
296
+ }
297
+ if (hasJank) {
298
+ console.log(" • Avoid reading layout properties during scroll (getBoundingClientRect, offsetTop)");
299
+ console.log(" • Debounce or throttle scroll event handlers");
300
+ console.log(" • Move scroll-driven animations to CSS or use Animation Worklet");
301
+ console.log(" • Use content-visibility: auto for long lists or off-screen sections");
302
+ console.log(" • Prefer transform over top/left for animated elements during scroll");
303
+ }
304
+ }
305
+
306
+ console.groupEnd();
307
+
308
+ const cssAuditResult = auditScrollCSS();
309
+ return {
310
+ script: "Scroll-Performance",
311
+ status: "ok",
312
+ details: {
313
+ nonPassiveListeners: nonPassiveListeners.length,
314
+ cssAudit: {
315
+ smoothScrollElements: cssAuditResult.smoothScrollElements.length,
316
+ willChangeElements: cssAuditResult.willChangeElements.length,
317
+ contentVisibilityElements: cssAuditResult.contentVisibilityElements.length,
318
+ },
319
+ sessionCount: sessions.length,
320
+ ...(sessions.length > 0 ? {
321
+ avgFps: Math.round(sessions.reduce((a, s) => a + s.avgFps, 0) / sessions.length),
322
+ worstSessionFps: Math.round(Math.min(...sessions.map((s) => s.avgFps))),
323
+ totalDrops: sessions.reduce((a, s) => a + s.drops, 0),
324
+ } : {}),
325
+ },
326
+ };
327
+ };
328
+
329
+ // ─── INIT ────────────────────────────────────────────────────────────────────
330
+
331
+ console.log(
332
+ "%c📜 Scroll Performance Analysis Active",
333
+ "font-weight: bold; font-size: 14px;"
334
+ );
335
+ console.log(
336
+ " Scroll to measure FPS. Non-passive listener registrations will be warned."
337
+ );
338
+ console.log(
339
+ " Call %cgetScrollSummary()%c for the full report.",
340
+ "font-family: monospace; background: #f3f4f6; padding: 2px 4px;",
341
+ ""
342
+ );
343
+
344
+ const cssSnapshot = auditScrollCSS();
345
+ return {
346
+ script: "Scroll-Performance",
347
+ status: "tracking",
348
+ details: {
349
+ nonPassiveListeners: nonPassiveListeners.length,
350
+ cssAudit: {
351
+ smoothScrollElements: cssSnapshot.smoothScrollElements.length,
352
+ willChangeElements: cssSnapshot.willChangeElements.length,
353
+ contentVisibilityElements: cssSnapshot.contentVisibilityElements.length,
354
+ },
355
+ },
356
+ message: "Scroll performance tracking active. Scroll the page then call getScrollSummary() for FPS data.",
357
+ getDataFn: "getScrollSummary",
358
+ };
359
+ })();
@@ -0,0 +1,205 @@
1
+ ## Common Workflows
2
+
3
+ ### Complete Interaction Performance Audit
4
+
5
+ When the user asks for interaction analysis or "audit responsiveness":
6
+
7
+ 1. **Interactions.js** - List all user interactions with timing
8
+ 2. **Input-Latency-Breakdown.js** - Break down interaction phases
9
+ 3. **Long-Animation-Frames.js** - Detect blocking animation frames
10
+ 4. **LongTask.js** - Identify long tasks blocking the main thread
11
+ 5. **Scroll-Performance.js** - Measure scroll smoothness
12
+
13
+ ### INP Deep Dive
14
+
15
+ When INP is slow (>200ms) or the user asks "debug INP" or "slow interactions":
16
+
17
+ 1. **Interactions.js** - Identify which interactions are slow
18
+ 2. **Input-Latency-Breakdown.js** - Break down into input delay, processing time, presentation delay
19
+ 3. **Long-Animation-Frames.js** - Find animation frames >50ms that block interactions
20
+ 4. **Long-Animation-Frames-Script-Attribution.js** - Identify scripts causing the blocking
21
+ 5. **Long-Animation-Frames-Helpers.js** - Get detailed timing and attribution helpers
22
+
23
+ ### Scroll Jank Investigation
24
+
25
+ When the user reports "scroll jank", "choppy scrolling", or "scroll performance issues":
26
+
27
+ 1. **Scroll-Performance.js** - Measure scroll smoothness and frame drops
28
+ 2. **Long-Animation-Frames.js** - Detect frames causing jank (>50ms)
29
+ 3. **Layout-Shift-Loading-and-Interaction.js** - Check for layout shifts during scroll
30
+ 4. **Long-Animation-Frames-Script-Attribution.js** - Find scripts running during scroll
31
+
32
+ ### Main Thread Blocking Analysis
33
+
34
+ When the page feels unresponsive or the user asks "why is the page frozen":
35
+
36
+ 1. **LongTask.js** - List all tasks >50ms blocking the main thread
37
+ 2. **Long-Animation-Frames.js** - Correlate with animation frame timing
38
+ 3. **Long-Animation-Frames-Script-Attribution.js** - Attribute blocking to specific scripts
39
+ 4. Cross-reference with **webperf-loading** skill:
40
+ - JS-Execution-Time-Breakdown.js (script parsing/execution time)
41
+ - First-And-Third-Party-Script-Info.js (identify third-party blockers)
42
+
43
+ ### Layout Shift During Interaction
44
+
45
+ When the user reports "things move when I click" or CLS issues during interaction:
46
+
47
+ 1. **Layout-Shift-Loading-and-Interaction.js** - Separate loading vs interaction shifts
48
+ 2. **Interactions.js** - Correlate shifts with specific interactions
49
+ 3. **CLS.js** (from Core Web Vitals skill) - Measure total CLS
50
+ 4. Cross-reference with **webperf-media** skill:
51
+ - Image-Element-Audit.js (images without dimensions causing shifts)
52
+
53
+ ### Animation Performance Analysis
54
+
55
+ When animations feel sluggish or the user asks "debug animation performance":
56
+
57
+ 1. **Long-Animation-Frames.js** - Identify frames taking too long to render
58
+ 2. **Long-Animation-Frames-Helpers.js** - Detailed frame timing analysis
59
+ 3. **Long-Animation-Frames-Script-Attribution.js** - Find scripts delaying frames
60
+ 4. **Scroll-Performance.js** - If scroll animations are involved
61
+
62
+ ### Third-Party Script Impact on Interactions
63
+
64
+ When interactions are slow and third-party scripts are suspected:
65
+
66
+ 1. **Long-Animation-Frames-Script-Attribution.js** - Identify third-party scripts in long frames
67
+ 2. **LongTask.js** - Measure long task frequency
68
+ 3. Cross-reference with **webperf-loading** skill:
69
+ - First-And-Third-Party-Script-Info.js (list all third-party scripts)
70
+ - First-And-Third-Party-Script-Timings.js (measure script loading impact)
71
+ - Script-Loading.js (check for blocking scripts)
72
+
73
+ ## Decision Tree
74
+
75
+ Use this decision tree to automatically run follow-up snippets based on results:
76
+
77
+ ### After Interactions.js
78
+
79
+ - **If any interaction > 200ms** → Run **Input-Latency-Breakdown.js** on slow interactions; also run **webperf-core-web-vitals:INP.js** for official INP measurement
80
+ - **If many interactions > 200ms** → Main thread congestion, run:
81
+ 1. **Long-Animation-Frames.js** (blocking frames)
82
+ 2. **LongTask.js** (long tasks)
83
+ 3. **Long-Animation-Frames-Script-Attribution.js** (culprit scripts)
84
+ - **If specific interaction types are slow (e.g., click vs keyboard)** → Focus on that interaction type
85
+ - **If interactions occur during page load** → Cross-check with **webperf-loading:JS-Execution-Time-Breakdown.js**
86
+
87
+ ### After Input-Latency-Breakdown.js
88
+
89
+ - **If Input Delay > 50ms** → Main thread was busy, run:
90
+ 1. **Long-Animation-Frames.js** (what was blocking)
91
+ 2. **LongTask.js** (long task before interaction)
92
+ - **If Processing Time > 100ms** → Heavy event handlers, run:
93
+ 1. **Long-Animation-Frames-Script-Attribution.js** (which scripts)
94
+ 2. **webperf-loading:First-And-Third-Party-Script-Info.js** (third-party involvement)
95
+ - **If Presentation Delay > 50ms** → Rendering bottleneck, run:
96
+ 1. **Long-Animation-Frames.js** (frame rendering time)
97
+ 2. **Layout-Shift-Loading-and-Interaction.js** (check for layout work)
98
+
99
+ ### After Long-Animation-Frames.js
100
+
101
+ - **If many frames > 50ms** → Run **Long-Animation-Frames-Script-Attribution.js** to identify causes
102
+ - **If frames > 100ms** → Critical blocking, run:
103
+ 1. **Long-Animation-Frames-Script-Attribution.js** (detailed attribution)
104
+ 2. **LongTask.js** (related long tasks)
105
+ 3. **webperf-loading:JS-Execution-Time-Breakdown.js** (script execution cost)
106
+ - **If frames occur during scroll** → Run **Scroll-Performance.js** to measure impact
107
+ - **If frames occur during page load** → Cross-check with **webperf-loading:Event-Processing-Time.js**
108
+
109
+ ### After Long-Animation-Frames-Script-Attribution.js
110
+
111
+ - **If third-party scripts are causing long frames** → Run:
112
+ 1. **webperf-loading:First-And-Third-Party-Script-Info.js** (list all third-party scripts)
113
+ 2. **webperf-loading:Script-Loading.js** (check loading strategy)
114
+ 3. Recommend deferring or removing problematic scripts
115
+ - **If first-party scripts are causing long frames** → Recommend:
116
+ - Code splitting
117
+ - Debouncing/throttling event handlers
118
+ - Web Workers for heavy computation
119
+ - **If forced reflow/layout detected** → Analyze DOM manipulation patterns
120
+
121
+ ### After LongTask.js
122
+
123
+ - **If many long tasks (>5)** → Main thread is congested, run:
124
+ 1. **Long-Animation-Frames-Script-Attribution.js** (detailed attribution)
125
+ 2. **webperf-loading:JS-Execution-Time-Breakdown.js** (script execution analysis)
126
+ 3. **webperf-loading:First-And-Third-Party-Script-Info.js** (identify heavy scripts)
127
+ - **If long tasks > 500ms** → Critical blocking, investigate:
128
+ - Synchronous third-party scripts
129
+ - Heavy computation without Web Workers
130
+ - Excessive DOM manipulation
131
+ - **If long tasks correlate with interactions** → Run **Interactions.js** to see impact
132
+
133
+ ### After Scroll-Performance.js
134
+
135
+ - **If scroll FPS < 30** → Severe jank, run:
136
+ 1. **Long-Animation-Frames.js** (blocking frames during scroll)
137
+ 2. **Long-Animation-Frames-Script-Attribution.js** (scripts running on scroll)
138
+ 3. **Layout-Shift-Loading-and-Interaction.js** (layout work during scroll)
139
+ - **If scroll FPS 30-50** → Noticeable jank, investigate:
140
+ - Scroll event handlers
141
+ - Passive event listeners
142
+ - CSS will-change properties
143
+ - **If scroll FPS > 50** → Good, but check for layout shifts during scroll
144
+
145
+ ### After Layout-Shift-Loading-and-Interaction.js
146
+
147
+ - **If shifts occur during page load** → Cross-reference with **webperf-core-web-vitals:CLS.js**
148
+ - **If shifts occur during interaction** → This impacts INP and UX, investigate:
149
+ 1. Dynamic content insertion
150
+ 2. Images/ads loading without dimensions
151
+ 3. Font swaps (run **webperf-loading:Fonts-Preloaded-Loaded-and-used-above-the-fold.js**)
152
+ - **If shifts occur during scroll** → Run **Scroll-Performance.js** to measure impact
153
+
154
+ ### After Long-Animation-Frames-Helpers.js
155
+
156
+ This is a utility snippet, use results to:
157
+ - Understand frame timing in detail
158
+ - Identify precise script attribution
159
+ - Measure style/layout/paint phases
160
+ - No automatic follow-up, use data to inform next steps
161
+
162
+ ### Performance Budget Thresholds
163
+
164
+ Use these thresholds to automatically trigger follow-up analysis:
165
+
166
+ **INP Thresholds:**
167
+ - **Good**: ≤ 200ms → Monitor, no action needed
168
+ - **Needs Improvement**: 200-500ms → Run Input-Latency-Breakdown.js
169
+ - **Poor**: > 500ms → Run full INP debugging workflow (5 snippets)
170
+
171
+ **Long Animation Frames:**
172
+ - **Warning**: > 50ms → Run Long-Animation-Frames-Script-Attribution.js
173
+ - **Critical**: > 100ms → Run full main thread blocking workflow
174
+
175
+ **Long Tasks:**
176
+ - **Warning**: > 50ms → Monitor frequency
177
+ - **Critical**: > 200ms or >5 tasks per second → Run attribution and script analysis
178
+
179
+ **Scroll Performance:**
180
+ - **Good**: ≥ 50 FPS → Monitor
181
+ - **Needs Improvement**: 30-50 FPS → Run Long-Animation-Frames.js
182
+ - **Poor**: < 30 FPS → Run full scroll jank workflow
183
+
184
+ **Interaction Frequency:**
185
+ - **If >10 interactions/second** → User is actively interacting, prioritize INP optimization
186
+ - **If <1 interaction/5 seconds** → Interactions are rare, focus on first interaction responsiveness
187
+
188
+ ### Multi-Metric Correlation
189
+
190
+ When multiple interaction metrics are poor:
191
+
192
+ - **If Long Tasks AND Long Animation Frames both detected** → Shared root cause:
193
+ 1. Run Long-Animation-Frames-Script-Attribution.js
194
+ 2. Likely heavy JavaScript execution
195
+ 3. Consider code splitting or Web Workers
196
+
197
+ - **If INP slow AND CLS high** → Interaction-triggered layout shifts:
198
+ 1. Run Layout-Shift-Loading-and-Interaction.js
199
+ 2. Correlate shift timing with interaction timing
200
+ 3. Check for dynamic content insertion
201
+
202
+ - **If Scroll jank AND Long Animation Frames** → Scroll handlers blocking main thread:
203
+ 1. Run Long-Animation-Frames-Script-Attribution.js during scroll
204
+ 2. Check for non-passive scroll listeners
205
+ 3. Audit scroll-triggered animations