gruntjs - Hard cache busting of assets w/ Compass -
i have hard cache busting compass, i.e. have hash-suffixed assets.
compass using soft cache busting adding ?v
parameter in query string, apparently not supported every cdn service, , avoid , encode file hash directly in filename (myfile-2q7de.png
).
is possible ? current approach copy assets, hash them all, write mapping file , use in minimal sass extension real file path it's non-hashed path. works great, except spritesheets : makes compass add hash sprites class names, makes them unusable :
.sprite-myfile-2q7de { ... }
i should add i'm using grunt this.
compass adds hash cache buster in generated sprite sheets (eg icons-sf6a3361a01.png
).
for other images, can use following code in config.rb
, found in documentation:
asset_cache_buster |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
thus, scss code
.icon-cloud { background: image-url("weather-cloud.png") no-repeat 0 0; }
generates image embedded cache buster (weather-cloud-1365271586.png
):
.icon-cloud { background: url('../img/weather-cloud-1365271586.png') no-repeat 0 0; }
warning: compass doesn't duplicate or rename image. you'll have create rewrite rule allow web server serve image.
Comments
Post a Comment