简体   繁体   English

为什么内联脚本>外部样式表比外部样式表>脚本快?

[英]Why inline script > External stylesheet is faster than External stylesheet > Script?

1. stylesheet > Script 1.样式表>脚本

http://stevesouders.com/cuzillion/?c0=hc1hfff2_0_f&c1=hc1hfff2_0_f&c2=hb0wfff0_0_f&c3=hb0wfff0_0_f&c4=bi1hfff2_0_f&c5=bi1hfff2_0_f&t=1438003196394 http://stevesouders.com/cuzillion/?c0=hc1hfff2_0_f&c1=hc1hfff2_0_f&c2=hb0wfff0_0_f&c3=hb0wfff0_0_f&c4=bi1hfff2_0_f&c5=bi1hfff2_0_f&t=1438003196394

2. Script > stylesheet 2.脚本>样式表

http://stevesouders.com/cuzillion/?c0=hb0wfff0_0_f&c1=hb0wfff0_0_f&c2=hc1hfff2_0_f&c3=hc1hfff2_0_f&c4=bi1hfff2_0_f&c5=bi1hfff2_0_f&t=1438003184842 http://stevesouders.com/cuzillion/?c0=hb0wfff0_0_f&c1=hb0wfff0_0_f&c2=hc1hfff2_0_f&c3=hc1hfff2_0_f&c4=bi1hfff2_0_f&c5=bi1hfff2_0_f&t=1438003184842

My understanding was scripts block the parsing. 我的理解是脚本阻止了解析。 So having script before stylesheet will slow down the page load. 因此,在样式表之前使用脚本会减慢页面加载速度。 However in the above instance when I have inline script before the CSS files the page load faster? 但是在上述实例中,当我在CSS文件之前使用内联脚本时,页面加载速度更快了吗?

Can someone explain why? 有人可以解释为什么吗?

I am seeing the difference on two events 'DomContentLoaded' and 'Load' 我看到两个事件“ DomContentLoaded”和“ Load”的区别

Difference between Load event in the two case is approx 5-15ms ( Second one is faster ) But Difference between DomContentLoaded is 2.5s ( Second one is faster ). 两种情况下Load事件之间的差异约为5-15ms(第二个更快),但DomContentLoaded之间的差异为2.5s(第二个更快)。 I am not sure, Reason behind this should be script is parsed before the css starts downloading from the network. 我不确定,背后的原因应该是在CSS开始从网络下载之前先解析脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM