【问题标题】:load piece of script very last最后加载一段脚本
【发布时间】:2012-07-01 18:54:16
【问题描述】:

我正在为客户端使用这个糟糕的 API。它将 HTML/JS 打包到 iPad 应用程序中。

我正在使用 iScroll,但它会干扰内置滚动机制。他们提供了一些代码来禁用滚动,但它仅在加载所有其他脚本后才有效(API 说)。

我的代码结构

<head> 
  <script src="scripts1.js"></script>
  <script src="scripts2.js"></script>
  <script src="scripts3.js"></script>
</head>

<body>
  <script>
  //some page specific code
  </script>
</body>

我正在使用一些 jQuery,但它们的 API 是纯 JavaScript。我如何在最后执行他们的代码?我试着把它放在页面的末尾,但是没有用。不确定使用超时是否合适?

【问题讨论】:

    标签: jquery time zepto iscroll


    【解决方案1】:

    您可以使用JQuery.getScript 并在成功函数中获取其他脚本。 它应该看起来像这样:

     $.getScript('scriptss1.js', function() {
          $.getScript('scriptss2.js', function() {
                $.getScript('scripts3.js', function() {
               });
         });
     });
    

    【讨论】:

      【解决方案2】:

      你签出require.js了吗?

      【讨论】:

        【解决方案3】:

        另一种选择是添加延迟属性

        <script src="scripts1.js" defer="defer"></script>
        <script src="scripts2.js" defer="defer"></script>
        <script src="scripts3.js" defer="defer"></script>
        

        http://www.w3.org/html/wg/drafts/html/master/scripting-1.html#attr-script-defer

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-09-07
          • 1970-01-01
          • 1970-01-01
          • 2022-01-01
          • 2016-05-22
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多