webkit & Gecko
就Webkit 和 Gecko 来讲,主要的渲染流程大体一样
测试结果:
外部样式会阻塞后续脚本执行,直到外部样式加载并解析完毕
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script>var start = +new Date;</script>
<link href="http://udacity-crp.herokuapp.com/style.css?rtt=2" rel="stylesheet">
</head>
<body>
<script>
var end = +new Date;
alert(end-start); //
</script>
</body>
</html>
外部样式不会阻塞后续外部脚本的加载,但会阻塞外部脚本的执行
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script>var start = +new Date;</script>
<link href="http://udacity-crp.herokuapp.com/style.css?rtt=2" rel="stylesheet">
</head>
<body>
<script src="http://udacity-crp.herokuapp.com/time.js?rtt=1&a"></script>
<div id="result"></div>
<script>var end = +new Date;console.log(end-start);</script>
</body>
</html>
如果后续外部脚本含有async属性(IE下为defer),则外部样式不会阻塞该脚本的加载与执行
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script>var start = +new Date;</script>
<link href="http://udacity-crp.herokuapp.com/style.css?rtt=2" rel="stylesheet">
</head>
<body>
<script src="http://udacity-crp.herokuapp.com/time.js?rtt=1&a" async></script>
<script>var end = +new Date;console.log(end-start);</script>
</body>
</html>
建议:
1、脚本应该放在外部css的前面,不论脚本是内联还是外部(当然,最好是脚本放在body的最后面);
2、可以的话,外部css最好直接内联到页面。
有关于一些其他的详细内容不加以解析,请看相关资料!
参考资料:
http://velocity.oreilly.com.cn/2010/ppts/limufromTaobao.pdf
http://lifesinger.wordpress.com/
http://hikejun.com/blog/2012/02/02/js和css的顺序关系/
http://www.html5rocks.com/zh/tutorials/internals/howbrowserswork/
http://www.2cto.com/kf/201406/305852.html
http://www.w3cmm.com/dom/document-stylesheets-getstylesheet.html
https://www.cnblogs.com/dojo-lzz/p/3983335.html
https://www.xuecaijie.com/htmlcss/172.htm
其他相关资料:
十分钟读懂浏览器渲染流程
浅析浏览器渲染原理
我的小树林