Is it possible to run Google Page speed from the command line?
Asked Answered
E

3

12

Is it possible to run Google Page speed from the command line? If so, how? I'm interested in automating nightly or daily Google PageSpeed calls that will inform me after a commit or daily if I've caused a drop in the Google PageSpeed 'grade' (for a given page).

Essive answered 21/3, 2012 at 23:22 Comment(0)
T
16

It's possible to use the PageSpeed Insights from the command line:

Install via: $ npm install --global psi

Usage: $ psi <url> --key=<key> --prettyprint=<true> --userIp=<userIp> --locale=<locale> --strategy=<desktop|mobile>

Run it like this: $ psi http://stackoverflow.com

PageSpeed Desktop Insights CLI

Also for mobile insights: $ psi http://stackoverflow.com --strategy=mobile

PageSpeed Mobile Insights CLI

UPDATE: You can use the PageSpeed Insights within your local development environment (internet connection required) with grunt + grunt-pagespeed + ngrok. Checkout the sample project for grunt-pagespeed and ngrok for further information.

Note: Run $ ngrok -authtoken <your-token> 80 and check the web interface parameters to make sure to set the right port in your Gruntfile.js!

Terminable answered 19/9, 2014 at 9:11 Comment(2)
Darn, my original post isn't very clear. I'd rather test these things before they go to production or acceptance, say in a nightly build, or just locally. So no access via the internet to the instance unless it's ran from the command line, and can access localhost, ect.Essive
@Essive I've updated my answer and added an option for using PageSpeed in a local development environment. Not sure if this will work for you as it requires Grunt and an internet connection, but maybe you can give it a try :)Terminable
F
4

There is a Google Page Speed API. It won't work directly from a command line but you can easily write a script in your language of choice that will interact with the API.

Furgeson answered 21/3, 2012 at 23:28 Comment(0)
D
1

You can use curl to run PageSpeed from command line like so:

curl "https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://your_url/&prettyprint=true&strategy=mobile&key=your_api_key"

It will return human readable results in json. cmd-F "score" to locate the overall score.

Reference : Official Google api.

Dallasdalli answered 10/11, 2016 at 8:13 Comment(1)
please not that the API is now at v5Shrapnel

© 2022 - 2024 — McMap. All rights reserved.