20

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?

2
  • Do you have access to your webserver or applicationserver configuration or understands your webserver .htaccess ? Commented Feb 13, 2012 at 9:56
  • I could run Apache on a local machine when debugging Commented Feb 13, 2012 at 10:02

3 Answers 3

16

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The Incognito mode could work for simple projects but not everything. Disabling the cache or editing the .htaccess is actually a better solution. Thank you.
9

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.

1 Comment

Awesome! Could be app.myDevModeVariable && require.config({ urlArgs: "v=" + (new Date()).getTime() });
3

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

1 Comment

As I wrote in the question, this solution will make the debugging painful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.