May 2, 2013

f Comment

The Best Settings For Using Google PageSpeed Service

Amazon Google is one of the most innovative technology giants and they are trying to get into the field of CDN, or content delivery network. I am fortunate enough to try out their CDN service which is called Google PageSpeed Service, or PSS, with my website https://cppprogramming.chtoen.com/.

This website is filled with static HTML pages which are not updated very often. Therefore I decided to cache my content in the CDN for a year. When I do an update I'll simply invalidate the cache in the CDN.

Read on to see how I configure my site with Google PSS so you'll get an idea how to configure your site too.

If you'd like to know the most optimal settings for CloudFlare CDN please read my post on The Best Settings for CloudFlare CDN.
Step 1: Make sure your web server is responding with the correct headers
I am using NGINX as my web server. In the Nginx server configuration file I include a line 'expires 1y;' which basically injects the following HTTP headers in the response:

Cache-Control:max-age=31536000 # in seconds
Expires:Fri, 02 May 2014 03:33:38 GMT # one year from the current time

If adding 'expires 1y;' does not work read my post on Why is Nginx Expires Directive Not Working?
If you use Apache 2.2.21 you can put the following lines in your httpd.conf:

LoadModule headers_module modules/mod_headers.so
Header set Cache-Control "max-age=31536000"
Header set Expires "Fri, 02 May 2014 03:33:38 GMT"
Header unset Pragma

Questions?

What does Google PageSpeed Service do?
What Google PSS will do is cache my pages (per their FAQ will resources such as images, JavaScript and CSS.) for one year, but it always tells browser that it should never cache the page with the following HTTP header:

Cache-Control: max-age=0, private, no-cache
Because "Pagespeed Service respects the cache control headers for all resources and HTML that your site serves."

This means the browser will always try to get the latest copy of the resource from Google PageSpeed servers but Google PageSpeed servers will ONLY get the latest copy from your origin server when the resource expires after a year OR when you invalidate the Google PSS caches.

Google PageSpeed Service Weaknesses compared to CloudFlare
However as of the time of the writing I see the following problems with Google PageSpeed Service:

1. I cannot control what type of content to be cached. In contrast CloudFlare provides a tool to use semi regular expression to match URLs that I want cached.

2. There's no explicit way to tell whether a URL has been cached simply by examining the HTTP response headers. In contrast CloudFlare uses 'CF-Cache-Status:HIT' to tell us that their CDN's cache is being used to serve the request.

Hopefully Google will continue to improve their Google PageSpeed Service and eventually fix all these problems.

If you have any questions let me know and I will do my best to help you!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael