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
.
When the user asks about network performance, connection quality, or adaptive loading:
When implementing adaptive loading or the user asks "how to optimize for slow connections":
-
If effectiveType is "slow-2g" or "2g" → Very slow connection, recommend:
- Run webperf-loading:Critical-CSS-Detection.js (inline critical CSS)
- Run webperf-media:Image-Element-Audit.js (implement aggressive lazy loading)
- Run webperf-loading:Prefetch-Resource-Validation.js (remove prefetch to save bandwidth)
- Run webperf-core-web-vitals:LCP.js (LCP is heavily impacted by slow connections)
- Recommend minimal resource strategy
-
If effectiveType is "3g" → Moderate connection, recommend:
- Run webperf-loading:Find-render-blocking-resources.js (minimize blocking)
- Run webperf-media:Image-Element-Audit.js (responsive images)
- Run webperf-loading:Resource-Hints-Validation.js (optimize preconnect)
- Run webperf-core-web-vitals:INP.js (high latency can impact interaction responsiveness)
- Implement adaptive image quality
-
If effectiveType is "4g" or better → Good connection, recommend:
- Standard optimization practices
- Consider strategic prefetch for navigation
- Higher quality media is acceptable
-
If save-data is enabled → User explicitly wants to save data, recommend:
- Reduce image quality aggressively
- Disable autoplay videos
- Defer non-critical resources
- Remove prefetch/preload hints
- Show "high quality" toggle option
-
If RTT > 300ms → High latency, recommend:
- Run webperf-loading:TTFB.js (latency impacts TTFB)
- Run webperf-loading:TTFB-Sub-Parts.js (break down latency components)
- Run webperf-loading:Resource-Hints-Validation.js (preconnect critical for high RTT)
- Run webperf-loading:Service-Worker-Analysis.js (caching is critical for high latency)
- Minimize number of origins
- Use HTTP/2 or HTTP/3 for multiplexing
-
If downlink < 1 Mbps → Very limited bandwidth, recommend:
- Run webperf-media:Image-Element-Audit.js (aggressive compression)
- Run webperf-media:Video-Element-Audit.js (disable autoplay)
- Run webperf-loading:Prefetch-Resource-Validation.js (remove prefetch)
- Implement bandwidth-aware loading
-
If downlink > 10 Mbps → Good bandwidth, consider:
- Higher quality media
- Strategic prefetch
- Preloading next-page resources