Skip to content

Instantly share code, notes, and snippets.

@judofyr
Created September 25, 2012 15:07
Show Gist options
  • Save judofyr/3782489 to your computer and use it in GitHub Desktop.
Save judofyr/3782489 to your computer and use it in GitHub Desktop.
Cache busting with Sass
# Use as: sass -r ./bust_url.rb
require 'digest/md5'
module Sass::Script::Functions
def bust_url(url)
url = url.value
source = options[:filename]
dir = File.dirname(source)
file = File.join(dir, url)
hex = Digest::MD5.hexdigest(File.read(file))
Sass::Script::String.new("url(#{url}?#{hex[0, 10]})")
end
declare :bust_url, :args => [:string]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment