关于将
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.
还有这个:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。