aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb15
2 files changed, 14 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index e4e717c238..a1173568d8 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Cache asset ids. [Jeremy Kemper]
+
* Optimized named routes respect AbstractRequest.relative_url_root. #9612 [danielmorrison, Jeremy Kemper]
* Introduce ActionController::Base.rescue_from to declare exception-handling methods. Cleaner style than the case-heavy rescue_action_in_public. #9449 [norbert]
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 9e38b4a714..4742b54eb9 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -409,9 +409,18 @@ module ActionView
# Use the RAILS_ASSET_ID environment variable or the source's
# modification time as its cache-busting asset id.
def rails_asset_id(source)
- ENV["RAILS_ASSET_ID"] ||
- File.mtime(File.join(ASSETS_DIR, source)).to_i.to_s rescue ""
+ if asset_id = ENV["RAILS_ASSET_ID"]
+ asset_id
+ else
+ @@asset_id_cache[source] ||=
+ if File.exist?(path = File.join(ASSETS_DIR, source))
+ File.mtime(path).to_i.to_s
+ else
+ ''
+ end
+ end
end
+ @@asset_id_cache = {}
# Break out the asset path rewrite so you wish to put the asset id
# someplace other than the query string.
@@ -451,4 +460,4 @@ module ActionView
end
end
end
-end \ No newline at end of file
+end