Skip to content
May 12 / Dan DeFelippi

Google Announces Page Speed Online API, W3 Total Cache Integration

Yesterday at the Google I/O conference the Page Speed team announced that it has added an API to Page Speed Online. For those who haven’t already tried it out, Page Speed Online is just like the browser plugin of the same name. It “analyzes the content of a web page, then generates suggestions to make that page faster” based on web performance best practices.

API Access

Google has created a getting started guide for setting up and accessing the API. You first need to enable the API from the Google APIs console. From there you can use your API key to submit requests. The API returns the results as JSON. Here’s an example from the guide:

Request:

$ curl "https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://code.google.com/speed/page-speed/&key=yourAPIKey"

Response:

{
 "kind": "pagespeedonline#result",
 "id": "http://code.google.com/speed/page-speed/",
 "responseCode": 200,
 "title": "Page Speed Home",
 "score": 90,
 "pageStats": {
  "numberResources": 22,
  "numberHosts": 7,
  "totalRequestBytes": "2761",
  "numberStaticResources": 16,
  "htmlResponseBytes": "91981",
  "cssResponseBytes": "37728",
  "imageResponseBytes": "13909",
  "javascriptResponseBytes": "247214",
  "otherResponseBytes": "8804",
  "numberJsResources": 6,
  "numberCssResources": 2
 },
 "formattedResults": {
  "locale": "en_US",
  "ruleResults": {
   "AvoidBadRequests": {
    "localizedRuleName": "Avoid bad requests",
    "ruleScore": 100,
    "ruleImpact": 0.0
   },
   ...
   "MinifyJavaScript": {
    "localizedRuleName": "Minify JavaScript",
    "ruleScore": 97,
    "ruleImpact": 0.1417,
    "urlBlocks": [
     {
      "header": {
       "format": "Minifying the following JavaScript resources could reduce their size by $1 ($2% reduction).",
       "args": [
        {
         "type": "BYTES",
         "value": "1.3KiB"
        },
        {
         "type": "INT_LITERAL",
         "value": "0"
        }
       ]
      },
      "urls": [
       {
        "result": {
         "format": "Minifying $1 could save $2 ($3% reduction).",
         "args": [
          {
           "type": "URL",
           "value": "http://code.google.com/js/codesite_tail.pack.04102009.js"
          },
          {
           "type": "BYTES",
           "value": "717B"
          },
          {
           "type": "INT_LITERAL",
           "value": "1"
          }
         ]
        }
       },
       ...
       {
        "result": {
         "format": "Minifying $1 could save $2 ($3% reduction).",
         "args": [
          {
           "type": "URL",
           "value": "http://www.gmodules.com/ig/proxy?url\u003dhttp%3A%2F%2Fjqueryjs.googlecode.com%2Ffiles%2Fjquery-1.2.6.min.js"
          },
          {
           "type": "BYTES",
           "value": "258B"
          },
          {
           "type": "INT_LITERAL",
           "value": "0"
          }
         ]
        }
       }
      ]
     }
    ]
   },
   ...
   "SpriteImages": {
    "localizedRuleName": "Combine images into CSS sprites",
    "ruleScore": 100,
    "ruleImpact": 0.0
   }
  }
 },
 "version": {
  "major": 1,
  "minor": 11
 }
}

W3 Total Cache Integration

The WordPress W3 Total Cache plugin was updated to include integration with Page Speed Online. If you run a WordPress blog you should be using this fantastic plugin. To get your API key head to the Google APIs console. Go the the “API Access” link in the left column and you’ll find your Simple API Access key near the middle of the page. Once added W3 Total Cache will add a new panel to the dashboard with the performance analysis:

Yes, I know this blog is only 92/100. That will be improving soon 🙂