LoginSignup
13
11

More than 5 years have passed since last update.

Compass の asset_cache_buster で付けるパラメータを MD5ハッシュに変更する

Last updated at Posted at 2013-05-31

デフォルトのままだとタイムスタンプが使われるので、複数人でコンパイル済みCSSをバージョン管理している場合に余計な差分が発生してしまう。

config.rbに以下を追加。

config.rb
asset_cache_buster do |path, file|
  if File.file?(file.path)
    Digest::MD5.hexdigest(File.read(file.path))[0, 8]
  else
    $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(file.path)}"
  end
end
hoge.scss
p {
  background: image_url('hoge.png') no-repeat;
}
hoge.css
/* before */
p {
  background: url('/images/hoge.png?1369971442') no-repeat;
}

/* after */
p {
  background: url('/images/hoge.png?b68b9eca') no-repeat;
}
13
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
11