Giter VIP home page Giter VIP logo

psi's Introduction

psi Build Status

PageSpeed Insights with reporting

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

Install

$ npm install --save psi

Usage

const psi = require('psi');

// Get the PageSpeed Insights report
psi('theverge.com').then(data => {
  console.log(data.ruleGroups.SPEED.score);
  console.log(data.pageStats);
});

// Output a formatted report to the terminal
psi.output('theverge.com').then(() => {
  console.log('done');
});

// Supply options to PSI and get back speed and usability scores
psi('theverge.com', {nokey: 'true', strategy: 'mobile'}).then(data => {
  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 is 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|ta
    --locale     Locale results should be generated in
    --threshold  Threshold score to pass the PageSpeed tes
    --optimized  Get the URL of optimized resources
    --download   Download optimized resources

  Example
    $ psi todomvc.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 project, we recommend using ngrok.

License

Apache-2.0 - Copyright 2015 Google Inc

psi's People

Contributors

addyosmani avatar sindresorhus avatar samccone avatar christianhaller avatar jrcryer avatar benwiley4000 avatar callumlocke avatar dcorb avatar hemanth avatar joews avatar luisangonzalez avatar tombailey avatar

Watchers

Ray Lugo, Jr. avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.