Search code examples
cachingrequirejsamdsystemjs

SystemJS versioning for production and cache management (requirejs urlArgs alternative)


I would like to migrate to SystemJS from requirejs however I am failing to find a solution as requirejs have for module versioning. For example in production (ASP.Net website) I have set RequireJS like this:

require.config({
            baseUrl: "@Url.Content("~/Scripts/")",
            urlArgs: "buildNumber=@(File.GetLastWriteTime(ViewContext.Controller.GetType().Assembly.Location).ToBinary().ToString() + typeof(Foundation.MvcApplication).Assembly.GetName().Version)",
            ...
});

It guarantees that the file will be reloaded once the project is republished in the production environment, and kept that way until it is reloaded.

However, I did not find any solution for this for SystemJS (As SystemJS manage more types of modules, I would like to migrate to it).

Has anyone used SystemJS in production and had the same issue, do you know an "urlArgs" parameter (or plugin) in SystemJS?


Solution

  • Long story short: there were issues on github of SystemJS about cache bust. But thing are not offically implemeted yet. At the moment there is a custom hook, which can be easily added

    var buildNumber = 1234, // made your own build number
        systemLocate = System.locate;
    System.locate = function(load) {
      return Promise.resolve(systemLocate.call(this, load)).then(function(address) {
        return address + '?build='+buildNumber;
      });
    }
    

    EDIT fix typo