The urlArgs solution has problems. Unfortunately you cannot control all proxy servers that might be between you and your user's web browser. Some of these proxy servers can be unfortunately configured to ignore URL parameters when caching files. If this happens, the wrong version of your JS file will be delivered to your user.
I finally gave up and implemented my own fix directly into require.js. If you are willing to modify your version of the requirejs library, this solution might work for you.
You can see the patch here:
https://github.com/jbcpollak/requirejs/commit/589ee0cdfe6f719cd761eee631ce68eee09a5a67
Once added, you can do something like this in your require config:
var require = { baseUrl: "/scripts/", cacheSuffix: ".buildNumber" }
Use your build system or server environment to replace buildNumber
with a revision id / software version / favorite color.
Using require like this:
require(["myModule"], function() { // no-op; });
Will cause require to request this file:
http://yourserver.com/scripts/myModule.buildNumber.js
On our server environment, we use url rewrite rules to strip out the buildNumber, and serve the correct JS file. This way we don't actually have to worry about renaming all of our JS files.
The patch will ignore any script that specifies a protocol, and it will not affect any non-JS files.
This works well for my environment, but I realize some users would prefer a prefix rather than a suffix, it should be easy to modify my commit to suit your needs.
Update:
In the pull request discussion, the requirejs author suggest this might work as a solution to prefix the revision number:
var require = { baseUrl: "/scripts/buildNumber." };
I have not tried this, but the implication is that this would request the following URL:
http://yourserver.com/scripts/buildNumber.myModule.js
Which might work very well for many people who can use a prefix.
Here are some possible duplicate questions:
RequireJS and proxy caching
require.js - How can I set a version on required modules as part of the URL?