Skip to content

denar90/psi-ngrok

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5f3e385 · Sep 17, 2016

History

4 Commits
Sep 17, 2016
Sep 17, 2016
Sep 17, 2016
Sep 17, 2016
Sep 17, 2016
Sep 17, 2016
Sep 17, 2016
Sep 17, 2016

Repository files navigation

psi-ngrok

PageSpeed Insights with local project

Uses psi and ngrok for running PageSpeed Insights for locally run web application.

Inspired by

Install

$ npm install --save-dev psi-ngrok

Usage

const psiNgrok = require('psi-ngrok');

psiNgrok(config);

Usage with configuration

const psiNgrok = require('psi-ngrok');

const config = {
  pages: ['page1.html', 'page2.html'],
  onBeforeConnect: function() {
    // do somtheng before ngrok is connected to your host
  },
  //called if page passed `threshold` limit
  onSuccess: function(data) {
    console.log(data); // all PSI data about page
  },
  //called if page didn't pass `threshold` limit
  onError: function(error) {
    console.log(error); // error message
  },
  options: {
    threshold: 85
  }
};

psiNgrok(config);

API

psiNgrok([config])

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

config

Type: object

strategies

Type: array
Default: ['mobile', 'desktop']
Values: mobile, desktop

Strategies to use when analyzing the page.

pages

Type: array
Default: ['/']

List of local pages which will be analyzed.

port

Type: number
Default: 8000

Port local server running at.

onBeforeConnect

Type: function
Default: Function.prototype

Function called before ngrok is started.

Useful for running local server.

onSuccess

Type: function
Default: Function.prototype

Function called each time page(s) passed threshold limit. Has data argument which consist of all PSI data about page.

onError

Type: function
Default: Function.prototype

Function called each time page(s) didn't pass threshold limit. Has error argument - message about what went wrong.

options

Type: object

Pretty the same as psi options

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.

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.

MIT © Artem Denysov