在谷歌地图中,如果我们不使用"同步"和"推迟"会发生什么



我正在开发谷歌地图API。我添加了syncdefer以减少加载时间。但添加async后,会对其他部分产生影响。

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

如果我们不使用异步和延迟,将会发生什么。有人能给我指正确的方向吗?

如果不在脚本中使用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.

推迟的解释:
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.

最新更新