【问题标题】:In google Map If we not use `sync` and `defer` what will happen在谷歌地图中如果我们不使用`sync`和`defer`会发生什么
【发布时间】:2018-11-14 06:29:44
【问题描述】:

我正在研究谷歌地图 API。我添加了syncdefer 以减少加载时间。但添加async 后会影响到其他部分。

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" 
async defer></script>

如果我们不使用异步并延迟会发生什么。谁能指出我正确的方向?

【问题讨论】:

    标签: html css api google-maps


    【解决方案1】:

    如果不使用脚本中的async,脚本会被浏览器同步加载。但是,地图将毫无问题地加载。 正如 Google 文档中所述
    The async attribute lets the browser render the rest of your website while the Maps JavaScript API loads. When the API is ready, it will call the function specified using the callback parameter.

    defer的解释:
    This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing DOMContentLoaded. Scripts with the defer attribute will prevent the DOMContentLoaded event from firing until the script has loaded and finished evaluating.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 2019-09-30
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2012-04-24
      相关资源
      最近更新 更多