Javascript is cached in development mode with asset pipeline

梦想的初衷 提交于 2020-01-01 01:48:09

问题


I recently upgraded my application to rails 3.1 and generally everything seems to be working but one thing is driving me insane.

I have 2 main js files, we'll call them, application.js and main.js.

application.js has my manifest stuff in it and is loading in main.js. That's working fine. My problem is when i'm in development mode and i make a change to main.js, then refresh the page the site doesn't pick up the change. In order to pull in the change I have restart the rails server.

I have debug mode turned on in development, but I'm wondering if there's another setting i'm missing?

Anyone run into this before?


回答1:


I had the same issue, but config.action_controller.perform_caching was already set to false.

For me and another guy I was working with, the problem was that Chrome was caching the page despite the settings in Rails.

To fix it, we just closed the tab, opened a new tab, and visited the site again.




回答2:


I had the same issue and found that removing the asset digests in development fixed the issue. Make sure you set it to false in developmen.rb:

config.assets.digest = false



回答3:


I had the same problem, and I finally stumbled across something in my development.rb. I had config.action_controller.perform_caching set to true, and changing it to false solved the problem.




回答4:


Opening Chrome in incognito mode worked best for me. No need to open and close a tab. In incognito mode, chrome doesn't cache javascript.




回答5:


Also note that if you enable config.threadsafe, it will turn cache_classes on. So if your config/environments/development.rb file contains the following:

config.cache_classes = false
config.threadsafe!

Then you are turning off cache_classes and then turning it right back on. You will need to either comment out config.threadsafe (if you don't need it) like this:

config.cache_classes = false
# config.threadsafe!

Or, if you need threadsafe, reverse the order of these two configurations so that config_classes is really turned off:

config.threadsafe!
config.cache_classes = false

For more information, see http://tenderlovemaking.com/2012/06/18/removing-config-threadsafe.html




回答6:


Have a look at your development log and see what it says when the application.js is served.

It should look something like this for a normal request (you browsed to a page):

Started GET "/assets/application.js" for 127.0.0.1 at Fri Sep 30 12:13:27 +1300 2011
Served asset /application.css - 304 Not Modified (2ms)

If not you may have not set the pipeline options correctly. One of the production settings might be in the wrong place. Section 9 of the asset pipeline guide has a checklist of correct settings for a migrated app.




回答7:


I had the same issue, config.action_controller.perform_caching set properly. I also use Heroku and precompile assets for the Push to Heroku using: RAILS_ENV=production bundle exec rake assets:precompile After the push, when I started new work, I forgot to remove the precompiled assets using: sudo rm -r public/assets/*

So, no matter what I did to any of my .js files, they changes were not showing up.




回答8:


If above mentioned answers fail in your context..

make sure the caching is done by rails.. some times it does not detect changes in asset and serve the older cached version..

use rails c >> Rails.cache.clear
or simply delete the caches in tmp dir

[project_dir/tmp/cache/assets"]



来源:https://stackoverflow.com/questions/7618254/javascript-is-cached-in-development-mode-with-asset-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!