js在html页面中的引用位置思考

来源:互联网 发布:淘宝活动策划方案 编辑:程序博客网 时间:2024/06/11 20:08

1. 引入js在head标签之间
先加载js,后加载页面,页面内容加载延迟,用户体验差

<!DOCTYPE html><html>    <head>        <script type="text/javascript" src="..."></script>    </head>    <body></body></html>

2. 引入js在body标签最后
页面内容先呈现,后加载js,页面内容提前加载,用户体验较好

<!DOCTYPE html><html>    <head></head>    <body>    ...    <script type="text/javascript" src="..."></script>    </body></html>
原创粉丝点击