Created
April 20, 2010 09:06
-
-
Save tka/372217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@asset_timestamps_cache = {} | |
@@asset_timestamps_cache_guard = Mutex.new | |
# Use the RAILS_ASSET_ID environment variable or the source's | |
# modification time as its cache-busting asset id. | |
def rails_asset_id(source) | |
if asset_id = ENV["RAILS_ASSET_ID"] | |
asset_id | |
else | |
if @@cache_asset_timestamps && (asset_id = @@asset_timestamps_cache[source]) | |
asset_id | |
else | |
path = File.join(ASSETS_DIR, source) | |
asset_id = File.exist?(path) ? File.mtime(path).to_i.to_s : '' | |
if @@cache_asset_timestamps | |
@@asset_timestamps_cache_guard.synchronize do | |
@@asset_timestamps_cache[source] = asset_id | |
end | |
end | |
asset_id | |
end | |
end | |
end | |
# Break out the asset path rewrite in case plugins wish to put the asset id | |
# someplace other than the query string. | |
def rewrite_asset_path(source) | |
asset_id = rails_asset_id(source) | |
if asset_id.blank? | |
source | |
else | |
source + "?#{asset_id}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment