Proxy Resources

PageSpeed Service was turned off on August 3rd, 2015. Please see Turndown Information for PageSpeed Service.

Objective

Optimize caching and reduce round trip time by proxying through Google’s network and serving resources closer to the user.

PageSpeed rule

This rewriter implements the PageSpeed rules for minimizing round trip times and optimizing caching.

Description

This rewriter proxies resources referenced in the HTML documents and CSS resources on a website via Google's *-ps.googleusercontent.com domain. Relative URLs in these references are converted to absolute URLs before proxying.

The proxied URLs are modified to include a hash of the resource content in order to improve the cacheability of a web page's resources. When serving the resource, this rewriter modifies the HTTP header to extend the max-age value of the cacheable resource to 31536000 seconds (one year). When the site owner changes the resource content, then the URL for the rewritten resource will also change. The old content in the user's browser cache will not be referenced again, because it will not match the new name.

Only URLs of resources with public or no Cache-Control headers are converted to their proxied equivalent URLs. PageSpeed Service caches such resources with their original TTL values in its servers, and automatically refresh the content whenever the resources change. Note that resources with no-cache or private caching headers or Set-Cookie headers in their responses are not cached on our servers. For non-HTML resources with no Cache-Control headers, we cache extend the resource for a few minutes. This rewriter works best when you specify Cache-Control headers correctly for your resources.

Operation of this rewriter on different types of resources, and corresponding examples are given below.

Proxy CSS

This rewriter parses the HTML document and replaces all stylesheet references in <link> tags with their proxied equivalents.

The example below shows the HTML before rewriting:

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="styles/bold.css">
  </head>
  <body>
    <div class="bold">Hello World!</div>
  </body>
</html>

and after rewriting:

<html>
  <head>
    <link href="http://1-ps.googleusercontent.com/h/fast.pssdemos.com/styles/bold.css.pagespeed.ce.LPpzLxg8Oe.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <div class="bold">Hello World!</div>
  </body>
</html>

Proxy Images

This rewriter parses the HTML document and replaces all image URL references in <body>, <img>, <input> and <td> tags and background-image style attributes of all elements with their proxied equivalents.

The example below shows the HTML before rewriting:

<html>
  <body>
    <img src="images/Puzzle.jpg">
  </body>
</html>

and after rewriting:

<html>
  <body>
    <img src="http://1-ps.googleusercontent.com/h/fast.pssdemos.com/images/Puzzle.jpg.pagespeed.ce.TYvaJMloT9.jpg">
  </body>
</html>

Proxy JavaScript

This rewriter parses the HTML document and replaces all JavaScript URLs referenced in <script> tags with their proxied equivalents.

The example below shows the HTML before rewriting:

<html>
  <head>
    <script src="scripts/example.js">
  </head>
  <body>
  </body>
</html>

and after rewriting:

<html>
  <head>
    <script
    src="http://1-ps.googleusercontent.com/h/fast.pssdemos.com/scripts/example.js.pagespeed.ce._6x4rM7ZLD.js">
  </head>
  <body>
  </body>
</html>

Limitations

While serving images from your original domain, please ensure that the Content-Type http headers and the actual content are consistent. For e.g. if you specify the Content-Type http header as image/jpeg, then the content should in fact be a JPEG image. A mismatch will result in incorrect rendering of your pages.

Do not include generated proxied URLs (of the form http://*-ps.googleusercontent.com/*) directly on your webpages, since this may prevent your users from getting benefits as PageSpeed Service evolves. Since these URLs are versioned to get cache extension benefits, hard-coding these into your webpages will result in the versions not being refreshed correctly. This may lead to your pages loading slowly on repeat views.