[js][RequireJS]urlArgs配置

urlArgs: function (id, url) {
        var args = document.getElementById('grayParam').innerText;
        return (url.indexOf('?') === -1 ? '?' : '&') + 'system=plus' + args;
},
    
urlArgs:附加到RequireJS用于获取资源的URL的额外查询字符串参数。当浏览器或服务器配置不正确时,最有用的是缓存破坏。urlArgs的缓存实例缓存设置示例:
urlArgs: "bust=" +  (new Date()).getTime()
根据RequireJS 2.2.0,urlArgs能够是一个函数。若是一个函数,它将接收模块ID和URL做为参数,它应该返回一个字符串,该字符串将被添加到URL的末尾。若是没有参数,返回一个空字符串。必定要照顾加入'?' 或“&”,具体取决于URL的现有状态。例:
requirejs.config({
    urlArgs: function(id, url) {
        var args = 'v=1';
        if (url.indexOf('view.html') !== -1) {
            args = 'v=2'
        }

        return (url.indexOf('?') === -1 ? '?' : '&') + args;
    }
});
在开发过程当中,使用此功能很是有用,但请务必在部署代码以前将其删除。

urlArgs: Extra query string arguments appended to URLs that RequireJS uses to fetch resources. Most useful to cache bust when the browser or server is not configured correctly. Example cache bust setting for urlArgs:
urlArgs: "bust=" +  (new Date()).getTime()
As of RequireJS 2.2.0, urlArgs can be a function. If a function, it will receive the module ID and the URL as parameters, and it should return a string that will be added to the end of the URL. Return an empty string if no args. Be sure to take care of adding the '?' or '&' depending on the existing state of the URL. Example:
requirejs.config({
    urlArgs: function(id, url) {
        var args = 'v=1';
        if (url.indexOf('view.html') !== -1) {
            args = 'v=2'
        }

        return (url.indexOf('?') === -1 ? '?' : '&') + args;
    }
});
During development it can be useful to use this, however be sure to remove it before deploying your code.
相关文章
相关标签/搜索