Web developers often use Google PageSpeed Insights to find out website performance and user experience. You can create your own customized tools like pagespeed insights using pagespeed insights API.
Google PageSpeed Insights API Key?
To use pagespeed insights API you first need to retrieve an API key. API keys helps you to track the number of requests made by your custom application and also helps google to track who is using their API.
Google PageSpeed Insights API key can be retrieved from Google developers console.
The pagespeed insight API is a URL which returns JSON data about your webpage performance and user experience.
This is the URL:
- url: pass the url of the webpage for which you need to performance and user experience data.
- key: pass the API key.
- strategy: strategy can be mobile or desktop.
Now making a request to this page will return JSON data. The JSON object contains information like server response code, final URL, score, pagestats(resources size and number of downloads) and finally pagespeed insight rules(pagespeed uses certain rules to calculate the webpage performance and user experience) along with their warning, error or success messages.
Every warning and error rule will have a impact value which shows the priority of solving that problem.
Let’s make AJAX request to the URL and display the returned JSON object: