Does anyone know how exactly the asset digest value is calculated? If I have two JS files which contain various other included JS scripts then will each file maintain the same digest hash if none of the inner scripts have been changed? Or is a new digest value calculated each time the assets:precompile operation is run?
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
Generally asset is anything that browser loads after it gets the HTML page. Meaning javascript, css and any images. But as you pointed out there are two different image types in a rails project.
The accepted answer is not quite true. We build static assets for our staging, demo and production servers, and the same asset is given different digest values in each case.
It turns out that the Rails environment is also being taken into consideration. Sprockets creates the digest as follows:
# Sprockets::Environment::initialize
@digest_class = ::Digest::MD5
# Sprockets::Base::digest
@digest ||= digest_class.new.update(VERSION).update(version.to_s)
# Sprockets::Base::file_digest(path)
digest.file(path.to_s)
# Sprockets::Asset::initialize
@digest = environment.file_digest(pathname).hexdigest
Rails hooks into Sprockets as follows:
# Sprockets::Railtie
app.assets = Sprockets::Environment.new(app.root.to_s) do |env|
env.version = ::Rails.env + "-#{config.assets.version}"
...
end
So rails is creating a Sprockets environment that has a version equal to the Rails environment, and Sprockets uses the version when creating the digest class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With