page insights improve performance code example
Example: fetch mobile speed and desktop speed score from google insights
You can return all possible audit categories using the following example:
1. URL: https://www.google.com/
2. Return-Fields: lighthouseResult/categories/*/score
* is a wildcard
3. Indentations (PrettyPrint): no
4. Strategy: Desktop
5. Categories: Performance | Progressive Web App (PWA) | Best practices |
Accessibility | SEO
6. Api-Key: {YOUR_API_KEY}
https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https%3A%2F%2Fstackoverflow.com%2F&fields=lighthouseResult%2Fcategories%2F*%2Fscore&prettyPrint=false&strategy=desktop&category=performance&category=pwa&category=best-practices&category=accessibility&category=seo&key={YOUR_API_KEY}
And the JSON-Response looks like this:
{
"lighthouseResult": {
"categories": {
"performance": {
"score":0.99
},
"accessibility": {
"score":0.7
},
"best-practices": {
"score":0.77
},
"seo": {
"score":0.9
},
"pwa": {
"score":0.56
}
}
}
}