开发者

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

I'm currently playing around with a build / deployment script for minifying static resources. Following good practice I'd like to set an expire header far into the future for most of my javascript, stylesheet and images.

To my question, when one or more of the static files has changed clients should ask for the newest version of the file. Will adding something like /css/style.css ?1235 after the url be enough to trigger a new reque开发者_如何学Pythonst? Or do I have to rename all my static files for each build (something like /css/style _12345.css)?

Update: Just to clarify, the reason that I'm asking is that I've noticed that a lot of other deployment scripts seems to take the "hard" path by renaming each file.


Will adding something like /css/style.css ?1235 after the url be enough to trigger a new request?

Yes, of course.

You can do it like this:

style.css?UNIXTIMESTAMP

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


RFC 2616 3.2 Uniform Resource Identifiers says:

As far as HTTP is concerned, Uniform Resource Identifiers are simply formatted strings which identify--via name, location, or any other characteristic--a resource.

So, http://foo/bar is a different resource to http://foo/bar?baz.

Some URIs are treated as equivalent, so http://foo/bar?baz is the same resource as http://foo/bar?BAZ (see 3.2.3 URI Comparison).

HTTP does contain some caching exceptions for handling the query part (see 13.9 Side Effects of GET and HEAD). I understand these to only apply to the exact same query.


if you can use mod_rewrite i add a rule like this:

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

which rewrites any javascript, css or flash file back to the original name so

/css/style_1234.css

gets rewritten back to

/css/style.css
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜