Page speed - any problems with simply using defer attribute?

你离开我真会死。 提交于 2019-12-04 21:38:26
Chad Killingsworth

You can prevent a script from blocking during load by using the async attribute on modern browsers:

<script async
  src="https://maps.googleapis.com/maps/api/js?sensor=false&callback=apiloaded">
</script>

The defer attribute indicates not to load at all until the page DOM has completely loaded. Defer implies async.

For older browser support, the page speed code you linked is correct.

With the Google Maps API, you must use a callback parameter when loading the API asynchronously. This causes the api to use dynamic script insertion rather than document.write calls internally. You can specify an empty callback parameter as well.

A note on Page Speed

Page speed is an excellent tool to help optimize a web site. I listed the async attribute because it allows the maps api to be downloaded in parallel (non-blocking). Page speed recommendations may show the most common way to decrease load times, but they are definitely not the only way.

Optimizing map load times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!