我想使用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>
我做错了什么? 你使用哪个后备?
答案 0 :(得分:1)
根据fallback.io docs,您fallback.load
列表中的键必须是您正在加载的javascript库公开的变量名称。
fallback.load({libraries},{options})
期望是一个包含密钥值的对象的对象 库的窗口变量,值是获取的URL 图书馆来自。键必须是库的窗口变量名称 如果它是一个JavaScript库,你正在加载。这只是相关的 JavaScript库而不是StyleSheets,可以为StyleSheets命名 但是你请他们。例如,jQuery的关键是jQuery 因为window.jQuery在jQuery加载完成后存在。这是 需要为旧版浏览器提供支持。
所以不要做
'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'
],