More about Rails cache, the asset pipeline and javascript

I have installed a gem that assigns a javascript variable with a dynamic ruby (rails) variable, in this case it is the language locale I18n.locale.

Because the javascript files are precompiled and cached, I see that the variable is not being properly updated. So I have studied a bit how the cache works to see what is the best way to work around it.

1. Identifying the issue
Look for the cached javascript text in the files on your local development environment, I have found them in the tmp file

You can clear those with

rake tmp:clear

2. How to solve it
I have found good hints in this articles:

http://technicalpickles.com/posts/some-tips-for-caching-javascript-and-css-in-rails/

http://stackoverflow.com/questions/15378018/prevent-rails-3-2-11-asset-pipeline-from-caching

I need to put and exception and say “do not cache this file”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s