Skip to content
PageSpeed Insights with reporting
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Upgrade dependencies Mar 14, 2019
test Meta tweaks Mar 14, 2019
.editorconfig meta tweaks Apr 8, 2016
.gitattributes Meta tweaks Mar 14, 2019
.gitignore Update dependencies Jan 15, 2018
.npmrc Update dependencies Jan 15, 2018
.travis.yml Meta tweaks Mar 14, 2019
LICENSE
README.md Add psi-ngrok to the readme (#94) Mar 14, 2019
cli.js Meta tweaks Mar 14, 2019
index.js Meta tweaks Mar 14, 2019
package.json Upgrade dependencies Mar 14, 2019
screenshot.png ES2015ify and require Node.js 4 Feb 14, 2017

README.md

psi Build Status

PageSpeed Insights with reporting

Run mobile and desktop performance tests for your deployed site using Google PageSpeed Insights v4 with tidy reporting for your build process.

Install

$ npm install psi

Usage

const psi = require('psi');

(async () => {
  // Get the PageSpeed Insights report
  const data = await psi('https://theverge.com');
  console.log(data.ruleGroups.SPEED.score);
  console.log(data.pageStats);

  // Output a formatted report to the terminal
  await psi.output('https://theverge.com');
  console.log('Done');

  // Supply options to PSI and get back speed and usability scores
  const data2 = await psi('https://theverge.com', {
    nokey: 'true',
    strategy: 'mobile'
  });
  console.log('Speed score:', data.ruleGroups.SPEED.score);
  console.log('Usability score:', data.ruleGroups.USABILITY.score);
})();

As of PSI 2.x, we expose both the PageSpeed Insights speed and usability scores. The latter is based on usability rules that score a page based on factors like the presence of a sensible mobile viewport.

API

psi(url, [options])

Returns a promise for the response data from Google PageSpeed Insights.

url

Type: string

URL of the page for which the PageSpeed Insights API should generate results.

options

Type: Object

key

Type: string
Default: Free tier

When using this module for a production-level build process, registering for an API key from the Google Developer Console is recommended.

strategy

Type: string
Default: mobile
Values: mobile desktop

Strategy to use when analyzing the page.

locale

Type: string
Default: en_US

Locale results should be generated in.

threshold

Type: number
Default: 70

Threshold score to pass the PageSpeed test. Useful for setting a performance budget.

psi.output(url, [options])

Output the formatted report to the terminal.

Returns a promise for the response data from Google PageSpeed Insights.

url and options are the same as psi().

CLI

$ npm install --global psi
$ psi --help

  Usage
    $ psi <url>

  Options
    --key        Google API Key. By default the free tier is used
    --strategy   Strategy to use when analyzing the page: mobile|desktop
    --format     Output format: cli|json|tap
    --locale     Locale results should be generated in
    --threshold  Threshold score to pass the PageSpeed test
    --optimized  Get the URL of optimized resources
    --download   Download optimized resources

  Example
    $ psi https://addyosmani.com --strategy=mobile

Getting PSI into your build process

A sample Gulp project using PSI is available.

If you use Grunt, grunt-pagespeed is a task by James Cryer that uses PSI under the hood.

For testing local projects, we recommend using psi-ngrok or ngrok.

License

Apache-2.0 - Copyright 2015 Google Inc

You can’t perform that action at this time.