2.0.1
psi
2.0 is out and includes new support for the PageSpeed Insights V2 API, bringing mobile usability scores (do you have a mobile viewport? are your tap targets sized adequately?), the ability to download optimised assets for your site and more.
Install/Update
$ npm install --global psi
New Promise-based API
We've switched our core API over to using Promises (thanks to @callumlocke). Interacting with psi
is only slightly different to the way you're used to using it and now looks like this:
var psi = require('psi');
// get the PageSpeed Insights report
psi('theverge.com').then(function (data) {
console.log(data.ruleGroups.SPEED.score);
console.log(data.pageStats);
});
// Supply options to psi and get back speed and usability scores
psi('html5rocks.com', { nokey: 'true', strategy: 'mobile' }).then(function (data) {
console.log('Speed score: ' + data.ruleGroups.SPEED.score);
console.log('Usability score: ' + data.ruleGroups.USABILITY.score);
});
// output a formatted report to the terminal
psi.output('theverge.com').then(function () {
console.log('done');
});
Support for the PageSpeed API V2
Thanks to @christianhaller we now support the latest version of the PageSpeed Insights API. Amongst other things, this adds support for screenshots in the returned API response when using the screenshot
option:
psi('aerotwist.com', {
screenshot: 'true',
nokey: 'true',
strategy: 'mobile',
}).then(function (data) {
// Data URI for the screenshot
console.log(data.screenshot.data);
});
New CLI features
This release includes a few new CLI flags including the ability to download optimised resources for your current page or fetch the URL to this zipped up bundle. Thanks to @hemanth for working on support for this.
--download
now lets you download optimised resources for the current page as a ZIP file--optimized
gets you the URL of these optimised resources for use elsewhere
For example, here are some of the optimised assets we get back when running --download
against marvel.com, who have a particularly poor score on moblile:
This downloads an optimized.zip
file to the current directory containing optimized CSS, JS and image resources returned from the PageSpeed Insights service.
Wrapping up
I would also like to thank @sindresorhus for consistently helping with code reviews and assisting us with moving over to XO for style linting in this release. Thanks also goes out to James Cryer for updating grunt-pagespeed to use the latest version of psi
. Gulp and npm scripts users will of course be able to just use the module directly.