javascript – 在页面体中而不是在head元素中包含脚本有哪些缺点/问题?

前端之家收集整理的这篇文章主要介绍了javascript – 在页面体中而不是在head元素中包含脚本有哪些缺点/问题?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
关于将 javascript放入< head>内的优缺点已经发布了 entry元素与关闭正文标记之前的权利(< / body>).

但是我发现有时开发人员会将JavaScript代码放在HTML页面的任意位置.这似乎主要是由于懒惰.在页面的任意位置嵌入JavaScript代码有什么缺点?存在许多明显的缺点,例如没有缓存,重复使用较少等.在这方面您还能想到哪些其他缺点?

感谢asdvance.

解决方法

读这个:

http://groups.google.com/group/closure-library-discuss/browse_thread/thread/1beecbb5d6afcb41?hl=en&pli=1

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">&lt;/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.

还有这个:

Using DOMContentReady considered anti-pattern by Google

猜你在找的JavaScript相关文章