tags:

views:

1660

answers:

4

I was browsing the html of my favorite site...ahem...and I saw this in the markup:

<link href="/Content/all.min.css?d=20090107" rel="stylesheet" type="text/css" />

what does "?d=20090107" do? I'm assuming it's a date of some kind, but I'm not sure why it's in the path to the file. Any ideas?

+34  A: 

That is there to add some uniqueness to the filename, so that when they change the CSS file, they can change the extra bit to be totally sure that every client will reload the CSS rather than use a cached version.

The webserver will ignore the parameter and serve /Content/all.min.css normally

Note: While it's possible the CSS is dynamically generated, this is a common idiom for ensuring a reload, and given the parameter is a date, it seems quite likely.


Edit: Podcast 38 mentioned this...

We’ve been using the Expires or Cache-Control Header since we launched. This saves the browser round-trips when getting infrequently changing items, such as images, javascript, or css. The downside is that, when you do actually change these files, you have to remember to change the filenames. A part of our build process now “tags” these files with a version number so we no longer have to remember to do this manually.

Paul Dixon
A: 

This seems to be not a simple css file, but a programattically generated css that takes parameters. Just like a php/asp file, but the output is css instead of html.

Sebastian Dietz
this is possible, but paul dixons' is a much more common scenario
annakata
@annakata You are right. I wasn't accustomed to this technique.
Sebastian Dietz
+5  A: 

It's to "clear the cache" every time the style is updated. I would speculate that whoever is responsible for those styles increments it every time there is a change. It's because the browser sees a different URL in the style field, so it will grab the latest version, even though it's technically in the same place on the server.

As helpfully pointed out in the comments, css files often have their expiry set well into the future, this method is a nice sidestep to cache related headers.

Quite a useful trick.

Sam152
Yes, the server would be setting an expires header for the css files in the far future to prevent needless requests that would just return a not modified response. Thus, when the file actually does change, the server needs to tweak the file name to prevent a browser cache hit.
CurtainDog
+1  A: 

It is to make the browser think it is a new file every-time to it refreshes its cache.

Very useful when your stylesheets change regularly...

Pez Cuckow