Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging when using require.js cache

Tags:

Using require.js I noticed that often the dependencies are cached by the browser and don't get updated even if I force the page to completely reload (command+shift+R).

In order to have always the updated file, I made require.js ask for the files adding '?datestamp' after the url. The only problem with this approach is that the breakpoints don't remain in chrome or firebug after reloading, making the debug painful.

Do you have any suggestion?

like image 356
Ghigo Avatar asked Feb 13 '12 09:02

Ghigo


People also ask

How do I stop JS from being cached?

Answers. You can't prevent IE or for that matter any browser from caching Java Script file, you can only direct browser to always fetch latest version of Javascript file from the web server using the solution provided above. Tools->Internet Options. general tab->Settings and select the option "Every time ..."

Do JS files get cached?

JavaScript and CSS files are usually cached in the browser after the first access. The browser cache is used to store web application assets like images, CSS, and JS code on your computer's hard drive.

How do you cache something in JavaScript?

You can cache a resource using three methods add , addAll , set . add() and addAll() method automatically fetches a resource, and caches it, whereas in set method we will fetch a data and set the cache.


3 Answers

Actually there are some things you can do:

Either you disable your browser caching completely to test it. An easy way in e.g. Chrome is to open a Incognito Window (CTRL + SHIFT + N) similar to the Private Browsing mode in Firefox. However the more ideal solution for you should be listed here: Disabling Chrome cache for website development

Or you instruct your webserver to send no cache headers for javascript or some javascript files. One possibility is to use mod_expires with apache.

like image 127
fyr Avatar answered Sep 30 '22 12:09

fyr


I used

require.config({ urlArgs: "v=" +  (new Date()).getTime() });

This solved my problem, but you have to remember to remove it, before you goto production.

like image 29
P.M Avatar answered Sep 30 '22 12:09

P.M


I think you can use the urlArgs on required.config

quote from http://requirejs.org/docs/api.html#packages urlArgs: Extra query string arguments appended to URLs that RequireJS uses to fetch resources. Most useful to cache bust when the browser or server is not configured correctly. Example cache bust setting for urlA

like image 32
Shinya Koizumi Avatar answered Sep 30 '22 13:09

Shinya Koizumi