使用RequireJS for CDN避免URL缓存破坏参数

val*_*riu 6 requirejs

有没有办法删除外部CDN资源的URL缓存清除参数?

我希望我的库文件有缓存清除,但不能用于外部jquery cdn文件.现在我正在使用:requirejs.config({ urlArgs : "v1.1"});让缓存破坏.

有什么建议怎么做?

谢谢

Pau*_*ime 0

这无疑是迄今为止我回答过的最古老的问题!

我创建了这个小提琴来使用RequireJS contexts,但它似乎不起作用。

上下文可以从不同的路径加载模块,但是两者都调用require()使用缓存清除 ( urlArgs) 参数。

所以我的结论是你不能做你想做的开箱即用的事情。

http://jsfiddle.net/FXSSf/5/

// Fiddle to try and have two RequireJS contexts, one without cache bust for CDN and one with cache bust for 'our' files
// See http://requirejs.org/docs/api.html#multiversion

// ensure that $ is invalid to begin with
var $ = null;

var cdnRequire = require.config({
    paths: {
        "jquery": "http://code.jquery.com/jquery-1.9.1"
    },
    urlArgs: ""
});

var ourRequire = require.config({
    baseUrl: "https://gist.github.com/gitgrimbo/5130393/raw/b9402d4dfb00ff0ad3211f30681bb6d0411e4295",
    urlArgs: "ourRequire-" + new Date().getTime()
});

// cdnRequire should *not* use cache bust parameter
cdnRequire(["jquery"], function ($) {
    alert($.fn.jquery);
    // ourRequire *should* use cache bust parameter
    ourRequire(["gistfile1"], function (myModule) {
        alert(myModule);
    });
});
Run Code Online (Sandbox Code Playgroud)