File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -681,3 +681,52 @@ script元素会阻塞页面的下载。浏览器会同时下载好几个组件
681
681
</body>
682
682
</html>
683
683
684
+ ### HTTP分块
685
+
686
+ HTTP协议支持“分块编码”。它允许将页面分成一块一块发送。所以如果你有一个很复杂的页面,你不需要将那些每个站都多多少少会有的(静态)头部信息也等到所有的服务端工作都完成后再开始发送。
687
+
688
+ 一个简单的策略是在组装页面其余部分的时候将页面\< head\> 的内容作为第一块发送。也就是像这样子:
689
+
690
+ <!doctype html>
691
+ <html>
692
+ <head>
693
+ <title>My App</title>
694
+ </head>
695
+ <!-- end of chunk #1 -->
696
+ <body>
697
+ ...
698
+ <script src="all_20100426.js"></script> </body>
699
+ </html>
700
+ <!-- end of chunk #2 -->
701
+
702
+ 这种情况下可以做一个简单的发动,将JavaScript移回\< head\> ,随着第一块一起发送。
703
+
704
+ 这样的话可以让服务器在拿到head区内容后就开始下载脚本文件,而此时页面的其它部分在服务端还尚未就绪:
705
+
706
+ <!doctype html>
707
+ <html>
708
+ <head>
709
+ <title>My App</title>
710
+ <script src="all_20100426.js"></script> </body>
711
+ </head>
712
+ <!-- end of chunk #1 -->
713
+ <body>
714
+ ...
715
+ </html>
716
+ <!-- end of chunk #2 -->
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
You can’t perform that action at this time.
0 commit comments