Skip to content

Instantly share code, notes, and snippets.

@alekseykulikov
Last active July 2, 2023 14:20
Show Gist options
  • Save alekseykulikov/b5b88e4f8495c39cdcf39bc05d6b50c7 to your computer and use it in GitHub Desktop.
Save alekseykulikov/b5b88e4f8495c39cdcf39bc05d6b50c7 to your computer and use it in GitHub Desktop.
Extra features of PageSpeed Insights API

In this article, I would like to share three features of PageSpeed Insights (PSI), that is not easy to find in the official documentation. I discovered them while hacking on the Lighthouse plugin and integrating PSI to Treo.sh.

For a context, PSI is a simple yet powerful API by Google, that audits your page using Lighthouse and provides real-world users' data from Chrome UX Report (CrUX).

1. Audit many categories with one request

By default, PSI API returns only performance category. It's possible to pass ?category argument multiple times and get a report with many Lighthouse categories using one request (available categories: performance, accessibility, best-practices, seo, pwa).

curl -i "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://treo.sh&category=pwa&category=seo"

2. Get Chrome UX Report data immediately

By default, PSI API triggers Lighthouse audit and it takes 10 to 20 seconds to get results.

If you just need CrUX data, like in the case of the field-performance plugin. Add origin: prefix before the actual URL and get origin-level results immediately:

curl -i "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=origin:https://www.google.com"

To get url-level data, prefix with url:

curl -i "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=url:https://www.google.com&strategy=mobile"

3. View real Lighthouse report

PSI provides a clean UI with field and lab performance data. But sometimes it's useful to see actual Lighthouse report, share, or export it.

Pass "?psiurl" argument to Lighthouse Viewer and it will fetch the PSI API and display the data in a default Lighthouse format.

Example link

Display PageSpeed Insights results using Lighthouse Viewer

I'm sure that there's more useful functionality, that is not easy to find in the official documentation. Share your tips in the comments or on Twitter @alekseykulikov_.

@alekseykulikov
Copy link
Author

@staabm, just added them: performance, accessibility, best-practices, seo, pwa.

@cpncc
Copy link

cpncc commented Jul 2, 2023

Please can someone help me with complete details on integrating pagespeed insights with wordpress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment