Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling asset fingerprinting with asset_path for a single asset

I want to use the normal asset name, e.g. app.js when calling the asset_path helper in my views. In production, it uses the cache-busting name, e.g. app-f73cf13e6f100eda6681381e7d3ae9eb.js.

Is there a way to get the normal name using asset_path?

like image 804
Calvin Avatar asked Jan 22 '12 09:01

Calvin


People also ask

What is asset fingerprinting?

Redesigning the Asset Delivery: Key Ideas File fingerprinting is a versioning technique that binds the name of a file to its actual content, usually by adding the file hash to the name (e.g. logo-idealo-kr3u2vv3k0r.

How do you Precompile an asset?

We use rake assets:precompile to precompile our assets before pushing code to production. This command precompiles assets and places them under the public/assets directory in our Rails application.

What is Require_tree?

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.

How do you Precompile in Rails?

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.


2 Answers

Figured it out, pretty simple actually. Just have to add digest: false to asset_path like so:

asset_path('app.js', digest: false)

like image 182
Calvin Avatar answered Sep 20 '22 15:09

Calvin


By default assets.digest is enable in production environment and is recommended for several reasons. However, if you really want to disable it write this in your production.rb

config.assets.digest = false  

For more info refer http://guides.rubyonrails.org/asset_pipeline.html

like image 35
DeathHammer Avatar answered Sep 18 '22 15:09

DeathHammer