views:

40

answers:

2

Hi,

I asked a question on http://stackoverflow.com/questions/1614429/what-is-style-cssver1-tag. I learned that developers use style.css?ver=1 to let browsers read updated css, but W.Craig Trader pointed out that is is not good.

My question is, what is the best way to force a browser to read updated css without style.css?Ver=1 format?

+3  A: 

Your server should take care of it. It will tell the browser when the file was last modified, and if the browser's cache is out of date, it will download the new version.

More in depth, each time the page loads, the browser does a head request on each item in the page (stylesheets, images..), which the webserver responds to by only sending the HTTP headers without the body, there is a header that specifies when the file was last modified (and possibly more about cache control), and if the browser's cache has a version of the file older than what the webserver says it has, it reloads that content.

Jeffrey Aylesworth
except if you have a far future expires header, which definitely reduces the number of requests made to the server.
barkmadley
+1  A: 

An option is to version the filename, like style-1.1.css.

Tordek