javascript – fallback.io不适用于脚本

我想使用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'
            ],

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...