RequireJS: Manage caching using ASP.NET assembly version
Fortunately, RequireJS has a parameter called urlArgs that you can use to append arguments to your script requests. The RequireJS documentation also states that this parameter can also be used to set some cache-busting values, such as the current time, to every script request. This will force the browser to re-download all required files on every request.
The solution I came up with is pretty simple. Use the project’s assembly version number as the urlArgs parameter value. Here’s how.
Add the following in your AssemblyInfo.cs file, if it’s not already present.
Then all you have to do is fetch this value, and use it as your urlArgs parameter value.
So every time you rebuild your project, it will cause the assembly version number to change. And that’s all the browser requires to force it to re-download all the files loaded via RequireJS. Pretty neat, huh.
This solution is ideal for ASP.NET projects mainly because it generates a different assembly version number on every build, but I’m sure there are ways to getting it working in other types of projects as well.