简体   繁体   English

需要JS,无法通过CDN加载库

[英]Require JS, Loading Libraries through CDN fails

I have read the answer to this question require js loading scripts from cdn fail . 我已阅读此问题的答案, 要求js从cdn加载脚本失败 But in my case it does not help. 但对我而言,这无济于事。 I have a require JS setup and I want to use CDN to load my libraries. 我有一个必需的JS设置,我想使用CDN加载我的库。 The Require JS documentation says below is the right way to load libs from CDN with a fallback to local files. 下面的Require JS文档说的是从CDN加载库并回退到本地文件的正确方法。

  requirejs.config({
    //To get timely, correct error triggers in IE, force a define/shim exports check.
    enforceDefine: true,
    paths: {
        jquery: [
            'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min',
            //If the CDN location fails, load from this location
            'lib/jquery'
        ]
    }
});


require(['jquery'], function ($) {
});

I am using the same method but I get an error instead, below is my code 我正在使用相同的方法,但出现错误,下面是我的代码

    requirejs.config({

    baseUrl: location.protocol + '//' + location.host + '/app',

    waitSeconds: 0,

    paths: {

        'jquery': ['https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min','/assets/js/vendor/jquery'],
        'jqueryPjax': '/assets/js/vendor/jquery.pjax',
        'jqueryUI': '/assets/js/vendor/jquery-ui.min',

        'jqueryMousewheel': '/assets/js/jquery.mousewheel',
        'jScrollPane': '/assets/js/jquery.jscrollpane.min',

        'fastclick': '/assets/js/vendor/fastclick',

        'jquerySlidebars': '/assets/js/jquery.slidebars.min',

        'imagesLoaded': '/assets/js/imagesloaded.pkgd.min',
        'fancyBox': '/assets/js/jquery.fancybox.pack',
        'fancyBoxThumb': '/assets/js/jquery.fancybox-thumbs',

        'text': '/assets/js/vendor/text',
        'chosen': '/assets/js/vendor/chosen',
        'bb': '/assets/js/vendor/backbone-min',
        'underscore': '/assets/js/vendor/underscore-min',
        'angular': '/assets/js/angular.min',


        'ventFactory': 'base/ventFactory',
        'util': 'base/util',
        'dom': 'base/dom',
        'actionHandler': 'base/actionHandler',
        'ajax': 'base/ajax'
    },

    shim: {
        'jquery': {
            exports: 'jQuery'
        },

        'jqueryUI': {
            deps: ['jquery']
        },

        'angular': {
            exports: 'angular'
        },

        'jqueryPjax': {
            deps: ['jquery'],
            exports: 'jQuery.fn.pjax'
        },

        'jqueryMousewheel': {
            deps: ['jquery'],
            exports: 'jQuery.fn.mousewheel'
        },

        'jScrollPane': {
            deps: ['jqueryMousewheel'],
            exports: 'jQuery.fn.jScrollPane'
        },

        'jquerySlidebars': {
            deps: ['jquery'],
            exports: 'jquerySlidebars'
        },

        'fancyBox': {
            deps: ['jquery'],
            exports: 'fancyBox'
        },
        'fancyBoxThumb': {
            deps: ['jquery', 'fancyBox'],
            exports: 'fancyBoxThumb'
        },
        'chosen': {
            deps: ['jquery'],
            exports: 'chosen'
        }
    }

});

requirejs(['jquery', 'app'], function($, app) {
    $(function() {
        app.start();
    });
});

I have just made the changes for Jquery as of now and I am giving both CDN URL and local path but when I load my page I get an error 到目前为止,我刚刚对Jquery进行了更改,同时提供了CDN URL和本地路径,但是在加载页面时出现错误

TypeError: $el.siblings is not a function TypeError:$ el.siblings不是函数

Adding on I am using Require JS for loading my libs but then at the production I am using almond, which combines all modules into one single file, so has this something to do with the error ? 另外,我使用Require JS来加载我的库,但是在生产环境中,我使用的是杏仁,它将所有模块组合到一个文件中,这与错误有关吗?

Any help on this is highly appreciated. 对此,我们将给予任何帮助。 Thanks 谢谢

Adding on I am using Require JS for loading my libs but then at the production I am using almond, which combines all modules into one single file, so has this something to do with the error ? 另外,我使用Require JS来加载我的库,但是在生产环境中,我使用的是杏仁,它将所有模块组合到一个文件中,这与错误有关吗?

Yes, it does. 是的,它确实。 Almond cannot do dynamic loading. 杏仁无法进行动态加载。 In other words, everything you want Almond to load must be into a single bundle of modules. 换句话说,您希望杏仁装载的所有东西都必须放在一个模块捆绑中。 You cannot use a CDN with Almond. 您不能将CDN与杏仁一起使用。

"No dynamic loading" is the first restriction in its list of restrictions . “无动态加载”是其限制列表中的第一个限制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM