PageSpeed Analyzer
Overview
Use this skill to audit site performance, identify issues, and prioritize fixes with repeatable runs of the local pagespeed_analyzer.py script.
Prerequisites
- Install Python dependencies:
pip install -r scripts/requirements.txt
- Create a Google API key for PageSpeed Insights:
- Use the official quickstart:
https://developers.google.com/speed/docs/insights/v5/get-started - Or manually:
Open Google Cloud Console.
Create or select a project.
Go to
APIs & Services->Library.Enable
PageSpeed Insights API.Go to
APIs & Services->Credentials.Create an API key.
Export one of these environment variables (preferred first):
PAGE_SPEED_INSIGHTS_API_KEY=your_key_here
PAGESPEED_API_KEY=your_key_here
Core Workflow
- Run the analyzer in
analysismode for actionable findings. - Start with both strategies unless the user asks for one.
- Use
summarymode for quick checks andfullmode only when raw payloads are required. - Prioritize fixes from weak categories, failing audits, and pinpoint URL-level evidence.
- Re-run after changes and compare mobile and desktop deltas.
Run Audits
Use wrapper script:
python scripts/run_pagespeed.py https://example.com --strategy both --mode analysis --output-format human --analyzer-path ../websites/pagespeed_analyzer.py
If websites/pagespeed_analyzer.py exists in the workspace root, --analyzer-path can be omitted.
Direct invocation is also valid:
python ../websites/pagespeed_analyzer.py https://example.com --strategy both --mode analysis --output-format human --api-key-env PAGE_SPEED_INSIGHTS_API_KEY,PAGESPEED_API_KEY
Recommended Defaults
- Use
--strategy bothunless user explicitly requests one strategy. - Use
--mode analysisfor optimization tasks. - Use
--output-format humanfor quick review. - Use
--output-format jsonfor automation or downstream parsing. - Keep retries enabled (
--max-retries 3or higher for unstable networks). - Use
--api-key-env PAGE_SPEED_INSIGHTS_API_KEY,PAGESPEED_API_KEYfor public, unambiguous key selection.
Troubleshoot Fast
- HTTP
429: treat as quota/rate limit; retry later or rotate to a valid key. - HTTP
5xxor network errors: rely on backoff flags and retry. - Missing key errors: set
PAGE_SPEED_INSIGHTS_API_KEYorPAGESPEED_API_KEY. - Empty/missing audit fields: surface
runtimeErrorand continue with available categories and metrics.
Interpreting Results
- Read
weakCategoriesfirst. - Then read
issuesByCategoryto find failing audits that affect category scores. - Use
pinpointsections (renderBlocking,unusedJavaScript,imageDelivery,longTasks,scriptTreemap) to identify exact URLs and byte/time hotspots. - Prioritize by largest user impact: render-blocking resources, JS waste, heavy images, long tasks, and high transfer payloads.
References
- references/command-recipes.md