Reputation: 85
I wanted to use the fallback.js from fallback.io, so I used the documentation from github. How ever the issue is that it works just the css and font files but it doesn't work for all my js scripts.
<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>
What did I do wrong? And which fallback do you use?
Upvotes: 4
Views: 524
Reputation: 596
According to the fallback.io docs, the keys in your fallback.load
list must be some variable name that's exposed by the javascript library you're loading.
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.
So instead of doing
'jquery-2.1.3.js': [
'//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js',
'media/js/jquery-2.1.3.js'
],
you should use
'jQuery': [
'//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js',
'media/js/jquery-2.1.3.js'
],
Upvotes: 1