Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript is cached in development mode with asset pipeline

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?

like image 730
JoshReedSchramm Avatar asked Oct 01 '11 04:10

JoshReedSchramm


People also ask

Does JavaScript get cached?

In general, most modern browsers will cache JavaScript files. This is standard practice for modern browsers and ensures an optimized loading experience. Cached assets such as JavaScript will typically be served from the browser's cache instead of making another request for a resource that has already been retrieved.

What is asset pipeline in JavaScript?

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 and pre-processors such as CoffeeScript, Sass, and ERB.

How do you Precompile an asset?

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.


1 Answers

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.

like image 51
Edward Anderson Avatar answered Sep 30 '22 09:09

Edward Anderson