Forum Moderators: not2easy

Message Too Old, No Replies

curious about how some people embed css files

         

issekun

10:46 am on Jun 24, 2008 (gmt 0)

10+ Year Member



from time to time when i inspect other people sourcecode i see css embedded as <link rel="stylesheet" type="text/css" media="screen" href="/css/style.css?3213546353" />

notice after the style.css a "?" is followed by a bunch of numbers... i'd like to know what is this about?

cudnt find an answer on google as well, so thought id ask here. i know it maybe a silly question - its just that i dun know wots its about.

thanks

WesleyC

6:57 pm on Jun 24, 2008 (gmt 0)

10+ Year Member



They're probably using a server-side language to process and serve the correct CSS file. Change the numbers and they'll serve a different file.

I've done this before in combination with browser sniffing to provide slightly different CSS files to different browsers, without the need for IE-only conditional comments. As a side benefit, it works for any browser, and can be done by any server-side language (assuming IIS or Apache web servers).

rocknbil

10:31 pm on Jun 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



notice after the style.css a "?" is followed by a bunch of numbers... i'd like to know what is this about?

As said, it's added by a server side program, but I propose a different reason - to absolutely prevent caching. It's an old trick we used to use on images, too.

A "certain" browser known for it's difficulties has a bad habit of not clearing the cache when it's supposed to, or even when you tell it to. If I update my site this week with a new style sheet that has the same name,

mystyles.css

This browser will not always "know" its a new version so it will use last week's version. If you use CSS for positioning, this can be disastrous.

So a server-side language can generate a unique number and tack it on as a query string even though the query string is not actually used for anything. This way, every time the style sheet loads, it points to a unique name

mystyles.css?1234567890

And forces the browser to download the new version instead of using the cached version.

This old trick is also useful for dynamic web sites where identical file names are used, but an image is replaced with a new version, as in a "picture of the day" application.

myimage.jpg?1234567890

This works on other browsers too. :-)

webfoo

11:23 pm on Jun 24, 2008 (gmt 0)

10+ Year Member



Yes, it's probably a dynamic stylesheet generated based on the string of numbers.

issekun

3:05 am on Jun 25, 2008 (gmt 0)

10+ Year Member



thank you all for answering, that help me clear a lot :)