amachree tamunoemi amachree tamunoemi - 2 years ago 77
jQuery Question

how to use urlArgs on one CDN link in require.config in presence of 2 or more paths to include from CDN

I wish to use two projects but my first priority is to load them from CDN network, so in my config path I need to load bowser, jquery, and html5shiv and facebook in a shim.

The value of the urlArgs in my config path is specifically for jquery to provide Subresource integrity (SRI).

But the urlArgs is appended to all the links and jquery works accidentally.

Will there be a way to use path specific urlArgs in presence of other paths?

My config is here below.

urlArgs: 'integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="&crossorigin="anonymous"',
shim: {
facebook : {
exports: 'FB'
paths: {
facebook: '',
jquery: [
// 'jquery',
if (bowser.msie && bowser.version < 9) {
appId : '1693650154217810',
status : true,
cookie : true,
xfbml : true,
oauth : true,
version : 'v2.5' // use graph api version 2.5
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse&&response.status==='connected'){
window.location.href = "http://localhost/influenza/scripts/loginset.php";
$("#influencer-login-social >:first-child a").on("click",function(){
FB.getLoginStatus(function(response) {
if (response.status !== 'connected') {
FB.login(function(response) {},{scope:'public_profile,email,user_friends'});
}, true)

Answer Source

You can write your own function to test the module id or the URL and return appropriate URL parameters to add or return an empty string. As per the documentation:

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:

    urlArgs: function(id, url) {
        var args = 'v=1';
        if (url.indexOf('view.html') !== -1) {
            args = 'v=2'

        return (url.indexOf('?') === -1 ? '?' : '&') + args;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download