sergeychernyshev / .htaccess

High performance drop-in .htaccess file for your site
601 stars 89 forks source link

Cache control #14

Closed gotardo closed 12 years ago

gotardo commented 12 years ago

Hello, I added a litlle change to the cache expiration config to set it on "modification plus 1 year". Regards!

sergeychernyshev commented 12 years ago

This is actually wrong as the goal of far-future expires is to make it stay in cache forever regardless of real expiration - in case you need to expire it, you should change the URL instead - that's why we have mod_rewrite rules to allow for name.ver.ext file names where "ver" is a virtual version that is actually just used for cache busting when you need that.

You can read the rationale behind this in my article in Performance Calendar 2010: http://calendar.perfplanet.com/2010/easy-cache-headers/

gotardo commented 12 years ago

Thanks, Sergei. I actually needed to use modification for a project in which some files my change without changing the name. So I think I will keep both ways of caching depending on the project. Kind regards.

sergeychernyshev commented 12 years ago

Well, this will not help anyway because you are setting expiration one year ahead, but can't predict when they will really expire.

For cases where you absolutely have to keep file names, you can use shorter expiration or use far future expiration and update technique discovered by Stoyan Stefanov and Steve Souders: http://www.stevesouders.com/blog/2012/05/22/self-updating-scripts/

gotardo commented 12 years ago

Hi Sergey, That's a really interesting article. In my case, I think it won't work because the use of an iframe and a second script just to check the availability of a new version will be too slow for a web that needs just a couple of scripts (large images are my real problem). Thanks a lot!

sergeychernyshev commented 12 years ago

Well, in this case, you should concentrate on changing the URLs - I built SVN assets, but you can also use simple fingerprinting as well - it allows for not adding too much of the process.