关于将
javascript放入< head>内的优缺点已经发布了
entry元素与关闭正文标记之前的权利(< / body>).
但是我发现有时开发人员会将JavaScript代码放在HTML页面的任意位置.这似乎主要是由于懒惰.在页面的任意位置嵌入JavaScript代码有什么缺点?存在许多明显的缺点,例如没有缓存,重复使用较少等.在这方面您还能想到哪些其他缺点?
感谢asdvance.
解决方法
读这个:
The short story is that we don’t want
to wait for DOMContentReady (or worse
the load event) since it leads to bad
user experience. The UI is not
responsive until all the DOM has been
loaded from the network. So the
preferred way is to use inline scripts
as soon as possible.
<div id="my-widget"></div> <script> initWidget(document.getElementById('my-widget')); </script>
Yes,it not as easy to
maintain but it leads to a better user
experience. By intentionally leaving
out DOMContentReady wrappers we have
been able to prevent Google Apps to
use on this anti pattern.
还有这个: