From 6b3ca3901cec07776a6c21bedd4989d268267017 Mon Sep 17 00:00:00 2001 From: Mattias Pfeiffer Date: Thu, 5 May 2011 10:14:21 +0200 Subject: [PATCH] Adding note about path based asset cache busting in to documentation --- .../configuration-reference.markdown | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/doc-src/content/help/tutorials/configuration-reference.markdown b/doc-src/content/help/tutorials/configuration-reference.markdown index af6d6ea7..3a966856 100644 --- a/doc-src/content/help/tutorials/configuration-reference.markdown +++ b/doc-src/content/help/tutorials/configuration-reference.markdown @@ -308,9 +308,12 @@ the asset host configuration is ignored. --- **`asset_cache_buster`** – Pass this function a block of code that defines the -cache buster strategy to be used. The block must return nil or a string that can -be appended to a url as a query parameter. The returned string must not include -the starting `?`. The block will be passed the root-relative url of the asset. +cache buster strategy to be used. The block must return nil, a string or a hash. +If the returned value is a hash the values of :path and/or :query is used to generate +a cache busted path to the asset. If a string value is returned, it is added as a query string. +The returned values for query strings must not include the starting `?`. + +The block will be passed the root-relative url of the asset. If the block accepts two arguments, it will also be passed a path that points to the asset on disk — which may or may not exist. @@ -324,6 +327,18 @@ that points to the asset on disk — which may or may not exist. end end +Busting the cache via path: + + asset_cache_buster do |path, real_path| + if File.exists?(real_path) + pathname = Pathname.new(path) + modified_time = File.mtime(real_path).strftime("%s") + new_path = "%s/%s-%s%s" % [pathname.dirname, pathname.basename(pathname.extname), modified_time, pathname.extname] + + {:path => new_path, :query => nil} + end + end + To disable the asset cache buster: asset_cache_buster :none