Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Manual google page speed

87 views

Published on

Manual google page speed

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Manual google page speed

  1. 1. Manual Google PageSpeed Install google APIS node.js npm install googleapis --save Install PageSpeed Insights with reporting npm install --save psi Usage var psi = require('psi'); // get the PageSpeed Insights report psi('html5rocks.com', function (err, data) { console.log(data.score); console.log(data.pageStats); }); // output a formatted report to the terminal psi.output('html5rocks.com', function (err) { console.log('done'); }); API psi(url, [options], callback) url Required Type: string URL of the page for which the PageSpeed Insights API should generate results. options Type: object key
  2. 2. Type: string Default: Free tier When using this module for a production-level build process, registering for an API key from theGoogle 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. callback(error, data) Required Type: function data Type: object The response from Google PageSpeed Insights. psi.output(url, [options], [callback]) Output the formatted report to the terminal. url and options is the same as psi().
  3. 3. callback(error) Type: function Install CLI $ npm install --global psi $ psi --help Usage psi <url> <options> Example psi todomvc.com --strategy=mobile 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. Install grunt-pagespeed npm install grunt-pagespeed --save-dev Loading the plugin Add this to your project's Gruntfile.js gruntfile: grunt.loadNpmTasks('grunt-pagespeed'); Or, add this to your project's Gruntfile.coffee gruntfile: grunt.loadNpmTasks 'grunt-pagespeed' Alternatively use load-grunt-tasks to load your plugins. require('load-grunt-tasks')(grunt); Pagespeed task Run this task with the grunt pagespeed command.
  4. 4. This task is a multi task so any targets, files and options should be specified according to the multi taskdocumentation. Usage Example pagespeed: { options: { nokey: true, url: "https://developers.google.com" }, 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 nokey Type: Boolean Use the nokey option to test-drive PageSpeed Insights before acquiring a key for production builds. key Type: String Google API Key url Type: String
  5. 5. The URL of the page for which the PageSpeed Insights API should generate results. 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 Sample output The grunt task outputs the results as follows if everything passes:
  6. 6. If the task fails to pass the threshold, then it ouputs something similar to the image below:

×