require.js - How can I set a version on required modules as part of the URL?

后端 未结 4 1877
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 06:50

I am using require.js to require JS modules in my application.

I need a way to bust client cache on new JS modules, by way of a different requested URL.

i.e., if

4条回答
  •  耶瑟儿~
    2021-01-21 07:08

    Just do it like the creator of requirejs suggests:

    var load = requirejs.load;
    requirejs.load = function (context, moduleId, url) {
      // modify url here
      url = url.substring(0, url.lastIndexOf('.')) + '.' + VERSION + url.substring(url.lastIndexOf('.'));
      return load(context, moduleId, url);
    };
    

    https://github.com/jrburke/requirejs/wiki/Fine-grained-URL-control

提交回复
热议问题