Requirejs加載超時問題的一個解決方法:設置waitSeconds=0

有時Requirejs會遇到加載js超時問題html

除了排查js腳本問題,網絡問題之外的一個解決方法是加大Require的等待時間waitSeconds,或者直接設置爲0,這個參數的意義是:The number of seconds to wait before giving up on loading a script. Setting it to 0 disables the timeout. The default is 7 seconds.api

引用別的帖子:網絡

Load timeout for modules, Likely causes and fixes:requirejs

There was a script error in one of the listed modules. If there is no script error in the browser's error console, and if you are using Firebug, try loading the page in another browser like Chrome or Safari. Sometimes script errors do not show up in Firebug.ui

The path configuration for a module is incorrect. Check the "Net" or "Network" tab in the browser's developer tools to see if there was a 404 for an URL that would map to the module name. Make sure the script file is in the right place. In some cases you may need to use the paths configuration to fix the URL resolution for the script.this

The paths config was used to set two module IDs to the same file, and that file only has one anonymous module in it. If module IDs "something" and "lib/something" are both configured to point to the same "scripts/libs/something.js" file, and something.js only has one anonymous module in it, this kind of timeout error can occur. The fix is to make sure all module ID references use the same ID (either choose "something" or "lib/something" for all references), or use map config.spa

解決方法:.net

  <script src="scripts/require.js"></script>
  <script>
  require.config({
    baseUrl: "/another/path",
    paths: {
      "some": "some/v1.0"
    },
    waitSeconds: 0
  });
  require( ["some/module", "my/module", "a.js", "b.js"],
    function(someModule,    myModule) {
      //This function will be called when all the dependencies
      //listed above are loaded. Note that this function could
      //be called before the page is loaded.
      //This callback is optional.
    }
  );
  </script> 

 

相關連接:code

1.http://stackoverflow.com/questions/8582314/requirejs-and-text-plugin-load-timeout-for-modules
2.http://stackoverflow.com/questions/20288007/load-timeout-for-modules-with-requirejs
3.官網API文檔:http://requirejs.org/docs/api.html#define
4.中文API文檔:http://requirejs.cn/docs/api.html#define
5.中文API文檔:http://makingmobile.org/docs/tools/requirejs-api-zh/#define
6.中文文檔:http://www.zfanw.com/blog/require-js.html
7.中文文檔:http://www.fanli7.net/a/bianchengyuyan/ASP/20130419/300243.html
8.http://requirejs.org/docs/api.html#config-waitSecondshtm

相關文章
相關標籤/搜索