A file and module loader for JavaScript
I'm a lot confused about CommonJS, AMD and RequireJS. Even after reading a lot.
I know that CommonJS (formerly ServerJS) is a group for defining some JavaScript specifications (i.e. modules) when the language is used outside the browser. CommonJS modules specification has some implementation like Node.js or RingoJS, right?
What's the relation between CommonJS, Asynchronous Module Definition (AMD) and RequireJS? Is RequireJS an implementation of CommonJS module definition? If yes, what's AMD then?
Source: (StackOverflow)
RequireJS seems to do something internally that caches required javascript files. If I make a change to one of the required files, I have to rename the file in order for the changes to be applied.
The common trick of appending a version number as a querystring param to the end of the filename does not work with requirejs <script src="jsfile.js?v2"></script>
What I am looking for is a way to prevent this internal cacheing of RequireJS required scripts without having to rename my script files every time they are updated.
Cross-Platform Solution:
I am now using urlArgs: "bust=" + (new Date()).getTime()
for automatic cache-busting during development and urlArgs: "bust=v2"
for production where I increment the hard-coded version num after rolling out an updated required script.
Note:
@Dustin Getz mentioned in a recent answer that Chrome Developer Tools will drop breakpoints during debugging when Javascript files are continuously refreshed like this. One workaround is to write debugger;
in code to trigger a breakpoint in most Javascript debuggers.
Server-Specific Solutions:
For specific solutions that may work better for your server environment such as Node or Apache, see some of the answers below.
Source: (StackOverflow)