January 31, 2014

Set Cache Header for Files Hosted on Google Code SVN

If you serve HTML, JavaScript, CSS and images from Google code using Subversion VCS, it might be a good idea to optimize HTTP caching by setting a longer expiry date. By default the server sets an expiry date of 3 minutes. It is possible to change this value by setting the google-cache-control:max-age subversion property on selected files (value specified in seconds). To specify a longer expiry date on files that do not change often, set this property to a higher value, e.g. 604800 (= one week). This allows the files to be saved or cached by a browser or proxy for a longer duration. To disable caching altogether set this property to 0.

Below are the response headers for a test file:

HTTP/1.1 200 OK
Date: Thu, 30 Jan 2014 12:59:21 GMT
Server: Apache
Last-Modified: Thu, 30 Jan 2014 12:58:07 GMT
ETag: "10//trunk/styles.css"
Accept-Ranges: bytes
Expires: Thu, 30 Jan 2014 13:02:21 GMT
Cache-Control: public, max-age=180
Content-Length: 4688
Content-Type: text/css

Below are the response headers for the same file with google-cache-control:max-age=604800:

HTTP/1.1 200 OK
Date: Thu, 30 Jan 2014 13:03:29 GMT
Server: Apache
Last-Modified: Thu, 30 Jan 2014 13:01:27 GMT
ETag: "11//trunk/styles.css"
Accept-Ranges: bytes
Expires: Thu, 06 Feb 2014 13:03:29 GMT
Cache-Control: public, max-age=604800
Age: 16
Content-Length: 4688
Content-Type: text/css

Setting File Properties Using TortoiseSVN

If you are using TortoiseSVN to manage your Google code hosted subversion repository, you can use the following instructions to set file properties such as google-cache-control:max-age and svn:mime-type:

  1. Locate (or search for) the files in Windows Explorer
  2. Select desired files and right-click
  3. In the context menu, click TortoiseSVN > Properties
  4. In the Properties dialog, click New > Other
  5. In the Add Properties dialog, enter (or select) Property name, Property value and click OK

Set file properties using TortoiseSVN step 1

Set file properties using TortoiseSVN step 2

Further reading: