SystemJS for version and cache management (urlArgs alternative required)

I would like to switch to SystemJS from requirejs, however I cannot find a solution, since requirejs have module version control. For example, in production (ASP.Net website), I installed RequireJS as follows:

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

This ensures that the file will be reloaded after the project is re-released in the production environment and will be stored until it is reloaded.

However, I did not find a solution for SystemJS for this (As SystemJS manages more types of modules, I would like to switch to it).

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

+9
caching requirejs amd systemjs
source share
2 answers

In short: there were problems with github SystemJS bust . But the matter is not over yet. At the moment there is a custom hook that you can easily add

 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 Correct a typo

+9
source share

I'm still on .19, and for my purposes I wanted to control the caching for specific files when importing, and not setting for the file or globally, etc., But literally, when I import, I want to manage it (for example, how do you will usually do with query strings).

So just to offer a small adaptation of the above, which, I think, is suitable for many people who want to do it this way - you can just conditionally enable “NO-CACHE” or something in any import, and the trap will add a temporary label to interrupt. cache. This allows you to call a module with a cache from one place, but without it from another. In addition, it allows you to disable the cache at any time during dynamic import, even dynamically.

 var systemLocate = System.locate; System.locate = function (load) { return Promise.resolve(systemLocate.call(this, load)).then(function (address) { if (address.includes('NO-CACHE')) return address.replace('NO-CACHE', '') + '?q=' + new Date(Date.now()).getTime(); return address; }); }; // Example Import with NO-CACHE - can be placed anywhere in path System.import('NO-CACHE../config.json!').then(config => { window.appVersion = config.version; }); 
0
source share

All Articles