在Google Map中,如果我们不使用`sync`和`defer`会发生什么

时间:2018-11-14 06:29:45

标签: html5 css3 api google-maps

我正在使用Google Map API。我添加了syncdefer以减少加载时间。但是添加async后,它将影响其他部分。

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

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

1 个答案:

答案 0 :(得分:0)

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