psi

PageSpeed Insights with reporting

  • 所有者: GoogleChromeLabs/psi
  • 平台:
  • 许可证: Apache License 2.0
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

psi Build Status

PageSpeed Insights with reporting

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

Install

$ npm install psi

Usage

const psi = require('psi');

(async () => {
  // Get the PageSpeed Insights report
  const { data } = await psi('https://theverge.com');
  console.log('Speed score:', data.lighthouseResult.categories.performance.score);

  // Output a formatted report to the terminal
  await psi.output('https://theverge.com');
  console.log('Done');

  // Supply options to PSI and get back speed
  const data2 = await psi('https://theverge.com', {
    nokey: 'true',
    strategy: 'desktop'
  });
  console.log('Speed score:', data2.data.lighthouseResult.categories.performance.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 are 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, tap
    --locale     Locale results should be generated in
    --threshold  Threshold score to pass the PageSpeed test

  Example
    $ psi https://addyosmani.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 projects, we recommend using psi-ngrok or ngrok.

License

Apache-2.0 - Copyright 2015 Google Inc

主要指标

概览
名称与所有者GoogleChromeLabs/psi
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证Apache License 2.0
所有者活动
创建于2014-05-26 22:05:17
推送于2021-04-10 00:13:45
最后一次提交2021-01-07 13:28:29
发布数26
最新版本名称v4.1.0 (发布于 2021-01-07 13:28:29)
第一版名称v0.0.1 (发布于 2014-06-01 23:33:48)
用户参与
星数3.1k
关注者数52
派生数126
提交数246
已启用问题?
问题数71
打开的问题数14
拉请求数46
打开的拉请求数1
关闭的拉请求数18
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?