ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript – fallback.io不适用于脚本

2019-07-08 11:35:00  阅读:362  来源: 互联网

标签:jquery javascript cdn twitter-bootstrap fallback


我想使用fallback.io中的fallback.js,所以我使用了github的文档.但问题是它只适用于css和字体文件,但它并不适用于我所有的js脚本.

<script src="media/js/fallback.min.js"></script>
<script>
    fallback.load({

        'jquery-2.1.3.js': [
            '//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js',
            'media/js/jquery-2.1.3.js'
        ],

        'bootstrap.min.js': [
            '//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js',
            'media/js/jquery-2.1.3.js'
        ],

        'smoothscroll.js': 'media/js/smoothscroll.js',

            'bootstrap.min.css': [
                '//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css',
                'media/css/bootstrap.min.css'
            ],

            'bootstrap-theme.min.css': [
                '//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css',
                'media/css/bootstrap-theme.min.css'
            ],

            'media.css': [
                'media/css/media.css'
            ],

            'Montesserat-Regular.ttf': [
                '//fonts.googleapis.com/css?family=Montserrat',
                'media/fonts/Montserrat-Regular.ttf'
            ] 
    }, 
    {
        // Shim jQuery UI so that it will only load after jQuery has completed!
        //'jQuery.ui': ['jQuery']
        shim: {
            'bootstrap.min.js': ['jquery-2.1.3.js'],
            'media.css': ['bootstrap.min.css'],
        },

        //callback: function(failed) {
            // success - object containing all libraries that loaded successfully.
            // failed - object containing all libraries that failed to load.
            // All of my libraries have finished loading!
            // Execute my code that applies to all of my libraries here!
        //}
    });

    //fallback.ready(['jquery-2.1.3.js'], function() {
        // jQuery Finished Loading
        // Execute my jQuery dependent code here! });

    //fallback.ready(['jQuery', 'JSON'], function() {
        // jQuery and JSON Finished Loading

        // Execute my jQuery + JSON dependent code here! });

    fallback.ready(['jquery-2.1.3.js', 'bootstrap.min.js'], function() {
        // All of my libraries have finished loading!
        $('.carousel').carousel({
            interval: 1000,
            pause: hover,
            wrap: true,
            keyboard: true
        })
        // Execute my code that applies to all of my libraries here!
    });
</script>
</head>

我做错了什么?
你使用哪个后备?

解决方法:

根据fallback.io docs,你的fallback.load列表中的键必须是一个由你正在加载的javascript库公开的变量名.

fallback.load({libraries}, {options})

Expects to be an object containing a key value pair where the key is
the library’s window variable, and the value is the url to fetch the
library from. The keys must be the window variable name of the library
you’re loading if it’s a JavaScript library. This is only relevant for
JavaScript libraries and not StyleSheets, for StyleSheets you can name
them however you please. For example jQuery’s key would be jQuery
since window.jQuery exists after jQuery has finished loading. This is
required to provide support for legacy browsers.

所以不要这样做

'jquery-2.1.3.js': [
                '//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js',
                'media/js/jquery-2.1.3.js'
            ],

你应该使用

'jQuery': [
                '//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js',
                'media/js/jquery-2.1.3.js'
            ],

标签:jquery,javascript,cdn,twitter-bootstrap,fallback
来源: https://codeday.me/bug/20190708/1401594.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有