Tuesday, June 9, 2009

SharePoint Blobcache and Browser max-age refresh settings

Most people know about the use of blobcache in Sharepoint for caching images, javascript and css. The other day i found a feature of blobcache which i wasnt aware of , which in turn solved a problem i had.

Blobcache effectively pulls all the specified images, css and javascript out from a given site and puts in on the local drive of the server, thus removing the latency of database calls and blob retrieval. This in itself is pretty cool and will speed up a site to some extent.

The problem i had was seemingly unrelated. Users of our MOSS site were complaining that images were being requested from the server for every page load or refresh and that this was causing alot of delays in loading pages. I fired up 'fiddler' and had a look at the header of the iis responses and noticed that the max-age value was set to zero, thus telling the browser not to cache any image, file or page coming from SharePoint. This makes sense for content pages, but seemed to be overkill for common images, css or javascript.

I researched the problem further and found a side benefit of using blobcache. To enable blobcache you edit the web.fig file and set the blobcache line to be enabled. for instance:

<blobcache enabled="true" path="\.(gif|jpg|png|css|js)$" location="C:\blobCache" maxsize="10">

I ran up some performance monitoring and sure enough, pages were loading alot faster. In fact, faster than i expected. I fired up fiddler again and discovered that for images, css and javascript the max-age value in the header was 86400. Effectively this tells the browser to cache these files for 1 day.

I read up more on blobcache and found that there is a parameter called max-age which if ommitted defaults to, you guessed it 86400. If 1 day is not right then you can specify your own time in seconds.

<blobcache enabled="true" path="\.(gif|jpg|png|css|js)$" location="C:\blobCache" maxsize="10" max-age="86400">

So using blobcache kills two birds with one stone. Not only does it remove the overhead of sql requests and responses by keeping the files locally, but it also allow the clients browser cache to store these files for a set period.

This solved my problem! I can only think that the blobcache feature should be turned on by default instead of off. Performace of pages in sharepoint is not the greatest and this makes a big difference, especially for WAN or remote users.

Matt

No comments:

Post a Comment