微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐