Avoid URL Caching Options with RequireJS for CDN

Is there a way to remove URL caching options for external CDN resources?

I want cache files for library files, but not for external jquery cdn files. Right now I'm using: requirejs.config({ urlArgs : "v1.1"}); to disable the cache.

Any suggestions on how to do this?

thanks

+6
source share
1 answer

This is by far the oldest question I have answered so far!

I created this script to use RequireJS contexts , but it does not work.

Contexts load modules from different paths in order, but both require() calls use the bust ( urlArgs ) parameter.

So my conclusion is that you cannot do what you want to do out of the box.

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); }); }); 
0
source

Source: https://habr.com/ru/post/912047/


All Articles