You know Rails has had this via asset timestamping for donkeys years?
Yeah, and it's BROKEN.
It's more that the *proxies* are BROKEN :) HTTP spec says not to cache
URIs with query strings, *unless* they contain expiration information.
All browsers will do the right thing, it's just proxy servers that
won't.
The definitive article on asset caching and timestamping, written by
Cal whilst he was at Flickr, is here:
http://carsonified.com/blog/features/webapps/serving-javascript-fast
It's also covered in High Peformance Web Sites:
http://www.amazon.com/dp/0596529309
and Steve Souder's blog article (the author of the above book):
http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
Rails uses query strings and mtimes by default so you don't need any
Rack middleware or rewrite rules to serve the assets from the front-
line web server. It works well if your users aren't using a proxy and
you're using remote_cache style deployment (where it's not a fresh
clone, with new mtimes, every time). It's not perfect, but a pretty
good default.
If you're using git and apache there's probably a better approach than
mtime, such as using the last commit SHA of each asset as the
asset_id. MD5'ing everything on deployment would work too.
If you simply want query-less asset timestamping in Rails you can
override the rewrite_asset_path helper:
http://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/asset_tag_helper.rb#L810
def rewrite_asset_path(source, path=nil)
source.gsub(/(\..+?)$/, '.' + rails_asset_id(source) + '\1')
end
Which will give you URLs such as:
/images/logo.1276407420.png
Rewrite in Apache like so:
RewriteRule (.+?)\.[0-9]+\.(css|js|gif|png|jpg)$ $1\.$2 [L]
-- tim
--
You received this message because you are subscribed to the Google Groups "Ruby or
Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.