make cache buster more robust
This commit is contained in:
parent
83d3456837
commit
9b050883e1
3 changed files with 34 additions and 30 deletions
|
@ -1,14 +1,18 @@
|
|||
class Middleman::Base
|
||||
after_feature_init do
|
||||
::Compass.configuration do |config|
|
||||
config.asset_cache_buster do |path, real_path|
|
||||
real_path = real_path.path if real_path.is_a? File
|
||||
real_path = real_path.gsub(File.join(self.root, self.build_dir), self.public)
|
||||
if File.readable?(real_path)
|
||||
File.mtime(real_path).strftime("%s")
|
||||
else
|
||||
$stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
|
||||
if self.respond_to?(:cache_buster?) && self.cache_buster?
|
||||
config.asset_cache_buster do |path, real_path|
|
||||
real_path = real_path.path if real_path.is_a? File
|
||||
real_path = real_path.gsub(File.join(self.root, self.build_dir), self.public)
|
||||
if File.readable?(real_path)
|
||||
File.mtime(real_path).strftime("%s")
|
||||
else
|
||||
$stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
|
||||
end
|
||||
end
|
||||
else
|
||||
config.asset_cache_buster { false }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,6 +25,8 @@ class << Middleman::Base
|
|||
def asset_url(path, prefix="", request=nil)
|
||||
http_path = pre_cache_buster_asset_url(path, prefix, request)
|
||||
|
||||
return http_path unless self.respond_to?(:cache_buster?) && self.cache_buster?
|
||||
|
||||
if http_path.include?("://") || !%w(.css .png .jpg .js .gif).include?(File.extname(http_path))
|
||||
http_path
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue