2015-03-18 68 views
4

我想使用fallback.io中的fallback.js,因此我使用了github中的文檔。問題在於它只能用於CSS和字體文件,但它不適用於我所有的js腳本。fallback.io不支持腳本

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

我做錯了什麼? 你使用哪種回退?

回答

1

根據fallback.io docs,您的fallback.load列表中的鍵必須是由您加載的JavaScript庫公開的某個變量名稱。

fallback.load({庫},{選項})

希望是含有鍵值對,其中關鍵是 庫的窗口變量的對象,並且該值是抓取的URL來自 的庫。如果它是JavaScript庫,則這些鍵必須是要加載的庫 的窗口變量名稱。這隻適用於 JavaScript庫,而不是StyleSheets,對於StyleSheets,您可以將它們命名爲 。例如,jQuery的關鍵將是jQuery ,因爲在jQuery加載完成後,window.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' 
      ],