CSS Files

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
Have seen this a few times lately, what is the purpose of adding kind of querystring data including a css file. E.g.

Code:
<link href="/css/style.css?65463456" media="screen" rel="Stylesheet" type="text/css" />

Ta
 
I would hazard a guess they have a few different ones (skins for example) and are storing the info in a db.
 
It could also be related to a crude form of CSS versioning.

CSS files are cached. Adding a random number to the filename using a querystring forces the browser to load that new CSS file.

eg revision #1 style.css?1
revision #2 style.css?2

and so on.
 
It could also be related to a crude form of CSS versioning.

CSS files are cached. Adding a random number to the filename using a querystring forces the browser to load that new CSS file.

eg revision #1 style.css?1
revision #2 style.css?2

and so on.

could you give an example of why someone woudln't want css to be cached?
 
I think he means that that number would stay the same, i.e. style.css?1 until the CSS is updated. At this point that number is updated in the HTML to force it to re-download the next time someone loads the page. It will then stay, cached, at style.css?2 until a new version is released.
 
It's a bad idea, because the benefit of having css in external files is that it allows for caching.

it's not a bad idea at all. your browser still caches the file. it's only when the css file is updated (and the html referencing it), that people will get a new version. Pho's post was very clear. how can you not understand it?
 
Yup its not about stopping CSS files being cached. Its really about forcing a CSS file to be redownloaded if its been changed.

Sometimes changes to an existing file don't appear as the browser still gets a cached version. By apending the querystring and changing its value. The browser sees it as new file.

It really just makes any changes get picked up instantly :)
 
I doubt that anyone has had 65million versions of a CSS file though :p whom ever has done it probably just wants to stop caching and didn't pay much regard to the pros and cons of doing so.
 
Last edited:
pin.gif
Page rank
5




pointer.gif


It's a bad idea, because the benefit of having css in external files is that it allows for caching.

tbh I'm thinking of doing this with client sites from now on. I'm sick of saying press ctrl and f5 to do a hard refresh :)

From what I can see it's good idea as:

  • Updates to my css file will show instantly
  • May be an idea to use it locally when developing a site - could add a random number to the css fill
Love learning little things like this, sad eh? :)
 
pin.gif
Page rank
5




pointer.gif




tbh I'm thinking of doing this with client sites from now on. I'm sick of saying press ctrl and f5 to do a hard refresh :)

From what I can see it's good idea as:

  • Updates to my css file will show instantly
  • May be an idea to use it locally when developing a site - could add a random number to the css fill
Love learning little things like this, sad eh? :)

nope, i'm the same. simple little things like this make life much easier. wish tehre was somewhere that had tips like this all in one place
 
If you want to be clever about it, you'll use the file's last updated datetime. That way you don't have to remember to manually update the reference.
 
Back
Top Bottom