views:

135

answers:

3

I am a web developer, have worked with PHP and .NET both. having over a year of experience working on web I haven't been able to understand the browser caching features thoroughly, I hope Web Gurus here can help me with it. Questions I have in my mind are :

  • How does browser actually caches stuff, does it request for to see if the cached file has changed on the server or not,
  • What is the Ideal way for a developer to make use of browser chaching to its full, but also to be able to push new changes on the site with no hassle at all. I think if browser somehow chaches my CSS and JS and Images, and then just makes a checks for their modification to the server everytime, this can sort the issue. but I am not sure how to do it,

waiting for interesting answers :)

+2  A: 

With CSS files a standard "workaround" is to incrementally add a parameter to a link:

<link rel="stylesheet" href="http://mysite.com/styles.css?v=1"&gt;
<link rel="stylesheet" href="http://mysite.com/styles.css?v=2"&gt;
...

This will force a browser to reload the file.

Developer Art
it wants me to add a query string again and again as i change my files, and with most of the sites these days we have many css and JS files loading, and many images, I will have to hire another dedicated resource to check and change the querystring daily then. :)
Umair
@Umair: You should be able to completely automate the query string, if you are working in PHP or .NET. If you are hard-coding the complete URL into static HTML files, it will be harder to do this, but then, your site isn't really so dynamic anyway.
Avi
will not the use of expires header, browser caching and last-modified-since save me the trouble of automating query strings
Umair
+1  A: 

This blog post may help:

http://blog.httpwatch.com/2007/12/10/two-simple-rules-for-http-caching/

It explains how to use of caching, whilst maintaining the ability to make changes when required.

HttpWatchSupport
I read this blogpost prior to asking this question, but it doesnt answer my questions because it wants me to add a query string again and again as i change my files, and with most of the sites these days we have many css and JS files loading, and many images, I will have to hire another dedicated resource to check and change the querystring daily then. :)
Umair
If you've got a lot resources that are changing then you would need some sort of automated system that updates the embedded URLs before deployment.
HttpWatchSupport