tags:

views:

73

answers:

3

StackOverflow implements it like this:

 <link rel="stylesheet" href="http://sstatic.net/so/all.css?v=4542"&gt;

Every time the referenced files change, the href attribute of the link tag is updated in the HTML code, thus supporting caching and updated referenced files.

My question - how do you retrieve the subversion version of that css file to include in the link? Subversion keywords only tell you the revision of the file you are currently in.

I'm working with PHP/CodeIgniter + jQuery.

A: 

Use what is called a svn commit hook. Sorry i dont got the details, but hopefully you can find those by googling.

Btw... you can use the timestamp of the file as cachebuster

index.php?p=blabla&v=".filemtime('mystyle.css') 
PHP_Jedi
+2  A: 

all.css is a static file.

The parameter is incremented each time the file is changed to make sure that the browser doesn't cache it incorrectly, as http://sstatic.net/so/all.css?v=4542 and http://sstatic.net/so/all.css?v=400 are seen as different files.

This is also commonly used in ad-networks where 'hits' are counted based on the number of times the graphic is downloaded, and browser caches would screw with the true value of views.

Thomas McDonald
Right, but how is that value programmatically retrieved?
Clayton
Jeff has said that the javascript files are run through the YUI compressor when the build script is run. My presumption would be that the js+css files are checked against the last version when the build script is ran to see if they have changed and if they have the 'version number' is incremented and stored in some form of constants file.
Thomas McDonald
A: 

Run the command svn info --xml /path/to/file, and look at the info/commit/revision. This is the last revision when that particular file changed.

Using the above, you can write a utility to create a mapping between js/css/img file and its version number. This mapping can then be loaded in php and appended as a query string like stackoverflow does.

The advantage of this approach is that the version will only change when the resource actually changes. You can therefore set aggressive cache headers - essentially telling the browser to cache the resource for ever.

sri