grunt-pagespeed

Grunt plugin for running Google PageSpeed Insights.

npm install grunt-pagespeed
30 downloads in the last day
71 downloads in the last week
222 downloads in the last month

grunt-pagespeed

Grunt plugin for running Google PageSpeed Insights

This plugin is developed for Grunt 0.4.1 and is not tested for backward compatibility with Grunt 0.3.x.

Getting Started

  1. Install this grunt plugin with the following command:

     npm install grunt-pagespeed --save-dev
    
  2. Add this to your project's Gruntfile.js gruntfile:

     grunt.loadNpmTasks('grunt-pagespeed');
    
  3. Obtain Google API Key from:

https://developers.google.com/speed/docs/insights/v1/getting_started#auth

Pagespeed task

Run this task with the grunt pagespeed command.

This task is a multi task so any targets, files and options should be specified according to the multi task documentation.

Usage Example

pagespeed: {
    prod: {
        options: {
            url: "https://developers.google.com/speed/docs/insights/v1/getting_started",
            locale: "en_GB",
            strategy: "desktop",
            threshold: 80
        }
    },
    paths: {
        options: {
            paths: ["/speed/docs/insights/v1/getting_started", "/speed/docs/about"],
            locale: "en_GB",
            strategy: "desktop",
            threshold: 80
        }
    },
    options: {
        key: "API_KEY",
        url: "https://developers.google.com"
    }
}

Target Properties

url

Type: String

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

locale

Type: String

The locale that results should be generated in. This is mandatory.

strategy

Type: String

The strategy to use when analyzing the page. Valid values are desktop and mobile.

threshold

Type: Number

Threshold score that is needed to pass the pagespeed test

paths

Type: Array

An array of URL paths that are appended to the URL

Options

key

Type: String

Google API Key

url

Type: String

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

Sample output

The grunt task outputs the results as follows if everything passes:

Passing task

If the task fails to pass the threshold, then it ouputs something similar to the image below:

Failing task

License

MIT

npm loves you