我的问题是加载google地图脚本:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXX&sensor=true"></script>
加载时间太长,导致页面渲染时间长达近3秒。我希望在页面完全渲染后再延迟加载外部脚本。将脚本放在页面底部,紧挨着标签也没有任何帮助。
我曾尝试使用getScript()函数,但它无法正常工作,并在调试控制台中抛出以下错误:
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
我已经在实际脚本标签中尝试了'defer'和'async',但仍然会抛出相同的错误。其他加载外部JS文件的方法也会导致相同的错误消息。
是否有可能的解决方法来解决这个问题?我甚至不知道错误声明是什么意思...