Moon
Moon

Reputation: 22605

How to control CSS cache?

I asked a question on what is style.css?ver=1 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?

Upvotes: 1

Views: 1066

Answers (2)

Tordek
Tordek

Reputation: 10882

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

Upvotes: 2

Jeffrey Aylesworth
Jeffrey Aylesworth

Reputation: 8510

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.

Upvotes: 3

Related Questions