In this second part in a short series of web site performance we cover versioning the resulting build dll to match that from Subversion. Minification and Concatination of JavaScript and CSS FilesVersioning Combined Files Using Subversion – this postVersioning Combined Files Using Mercurial – published shortly In the previous post we used AjaxMin to shrink js and css files then concatenated them into one file each which had the file name of site-script.combined.min.js and site-style.combined.min.css. These file names are fine, but you can configure IIS 7 to cache these static files and so lower the amount of data transferred between server and client. This is done by editing the response headers in IIS. 1. In IIS7 Manager, choose the directory where these files are located and select HTTP Response Headers.
1_thumb_0DA343DD
2. Check the Expire Web Content and set a time period well into the future.
2_thumb_0308072C
3. When refreshing the web page, the server will respond with HTTP 304 forcing the browser to retrieve the file from its cache.
3_thumb_6FE96B30
4. As can be seen in FireBug, the Cache-Control header has a max age of 31536000 seconds which equates to 365 days.
4_thumb_0AB821EE
The server will always send this HTTP 304 message unless the file changes forcing it to send new content. To help force this we can change the file name based on the latest build using the SVN revision number in the filename. So we have lowered data transfer on content that hasn’t changed, but forced it to be sent when you have made a change to the css or js files. Now to get the SVN revision number in to the file name. 1. Import the MSBuildCommunityTasks targets which can be dowloaded from here.

2. Edit the BeforeBuild target to call out to svn and get the latest revision

3. Set it to update the project AssemblyInfo.cs file for the svn revision.

4. Now edit the AfterBuild target to get the full dll version. You could combine these two steps and just get the version from svn, I am working on one project that updates the AssemblyInfo file and another project that allows manual editing of the file, but needs that version within the file name; so I just combined the two for this post.

5. Use this Info.AssemblyVersion to write out the combined css and js files as described in the last post.

In the next post I will cover doing the same, but for a Mercurial repository.