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','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',

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...