zoukankan      html  css  js  c++  java
  • Requirejs加载超时问题的一个解决方法:设置waitSeconds=0

    有时Requirejs会遇到加载js超时问题

    除了排查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.

    引用别的帖子:

    Load timeout for modules, Likely causes and fixes:

    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.

    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.

    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.

    解决方法:

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

    相关链接:

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

  • 相关阅读:
    记一次百度面试题
    深度拷贝对象
    spring boot 学习笔记
    mac Zip 常用命令
    Mac OS 终端下使用 Curl 命令下载文件
    懒人必备的移动端定宽网页适配方案
    前端面试题之 sum(2)(3) (链式调用,toString,柯里化,数组操作)
    web上的复制
    fileupload上传文件时带参数
    Mac下Nginx环境配置
  • 原文地址:https://www.cnblogs.com/liuzhendong/p/4502741.html
Copyright © 2011-2022 走看看