JavaScript snippets for measuring web performance in Chrome DevTools. Execute with
mcp__chrome-devtools__evaluate_script
, capture output with
mcp__chrome-devtools__get_console_message
.
-
If images missing width/height attributes → Layout shift risk, run:
- webperf-core-web-vitals:CLS.js (measure CLS impact)
- webperf-interaction:Layout-Shift-Loading-and-Interaction.js (timing of shifts)
- Recommend adding explicit dimensions to all images
-
If images using wrong format (JPEG for graphics, PNG for photos) → Recommend:
- Modern formats: WebP, AVIF
- Appropriate format for content type
- Format-specific compression settings
-
If images much larger than display size → Recommend:
- Responsive images with srcset
- Appropriate image CDN sizing
- srcset with multiple sizes for different viewports
-
If above-the-fold images are lazy-loaded → Run:
- webperf-loading:Find-Above-The-Fold-Lazy-Loaded-Images.js (confirm)
- webperf-core-web-vitals:LCP.js (measure LCP impact)
- Recommend removing loading="lazy" from above-fold images
-
If LCP image lacks fetchpriority="high" → Run:
- webperf-core-web-vitals:LCP.js (measure current LCP)
- webperf-loading:Priority-Hints-Audit.js (full priority audit)
- Recommend adding fetchpriority="high" to LCP image
-
If below-the-fold images are NOT lazy-loaded → Run:
- webperf-loading:Find-non-Lazy-Loaded-Images-outside-of-the-viewport.js (confirm)
- Recommend adding loading="lazy" to offscreen images
-
If images have both loading="lazy" AND fetchpriority="high" → Run:
- webperf-loading:Find-Images-With-Lazy-and-Fetchpriority.js (confirm contradiction)
- Recommend removing one of the conflicting attributes
-
If images competing with critical resources → Run:
- webperf-loading:Find-render-blocking-resources.js (resource priority conflicts)
- webperf-loading:TTFB-Resources.js (identify slow image CDN)
-
If images missing alt text → Accessibility issue, recommend adding descriptive alt text
-
If video is LCP candidate → Run:
- webperf-core-web-vitals:LCP-Video-Candidate.js (confirm)
- webperf-core-web-vitals:LCP.js (measure LCP)
- webperf-core-web-vitals:LCP-Sub-Parts.js (break down timing)
- Optimize video poster image or consider image alternative
-
If video missing poster → Recommend:
- Adding poster image for better perceived performance
- Using first frame or custom thumbnail
- Optimizing poster as you would an image
-
If video uses preload="auto" → Bandwidth concern, evaluate:
- Is video above-the-fold? Keep preload="auto"
- Is video below-the-fold? Change to preload="metadata" or "none"
- Is autoplay intended? Verify preload matches intent
-
If autoplay video without muted → Browser will block, recommend:
- Adding muted attribute
- Or removing autoplay
-
If video missing multiple formats → Recommend:
- WebM for Chrome/Firefox
- MP4 as fallback for Safari
- Order sources by efficiency (WebM first)
-
If large video files (>5MB) → Recommend:
- Compression/transcoding
- Adaptive bitrate streaming (HLS, DASH)
- Loading strategy optimization
-
If bitmap images found in SVGs → Recommend:
- Extract bitmaps to separate files
- Use WebP/AVIF format for extracted images
- Reference images from SVG with <image> element
- Or convert to pure vector if possible
-
If large embedded bitmaps (>100KB) → Critical inefficiency:
- SVG parsing overhead + large bitmap = worst of both worlds
- Urgently recommend extraction
-
If multiple small bitmaps in SVG → Consider:
- CSS sprites for small icons
- SVG symbols for reusable graphics
- Extracting to individual optimized images