Http caching - style.css? 123 or style_123.css?

I am currently playing with build / deploy script to minimize static resources. Following good practice, I would like to set the expire header in the future for most of my javascript, style sheets, and images.

To my question, when one or more static files changed, clients should request the latest version of the file. Will something like /css/style.css be added ? 1235 after the URL is enough to trigger a new request? Or do I need to rename all my static files for each assembly (something like / css / style _12345 .css)?

Update. To clarify, the reason I'm asking is because I noticed that many other deployment scenarios seem to take the "hard" path by renaming each file.

+4
source share
3 answers

RFC 2616 3.2 Uniform Resource Identifiers :

As for HTTP, Uniform Resource Identifiers are simply formatted strings that identify - through a name, location, or any other attribute - a resource.

So http://foo/bar is another resource for http://foo/bar?baz .

Some URIs are considered equivalent, so http://foo/bar?baz is the same resource as http://foo/bar?baz (see 3.2.3 Comparing URIs ).

HTTP contains some caching exceptions for processing part of the request (see 13.9 Side effects of GET and HEAD ). I understand that they apply only to the same query.

+2
source

Will something like /css/style.css be added? Is 1235 after the URL enough to trigger a new request?

Yes of course.

You can do it as follows:

style.css?UNIXTIMESTAMP

where UNIXTIMESTAMP is the time the file was created in timestamp unix format

+3
source

if you can use mod_rewrite, I add the following rule:

 RewriteRule ^/((.*)_[0-9]+(\.(?:js|css|swf).*))$ /$2$3 [NC,L] 

which overwrites any javascript, css or flash file back to the original name, therefore

 /css/style_1234.css 

texting back to

 /css/style.css 
0
source

All Articles