自寫 HTTP 服務器,Chrome 瞬間顯示頁面,360 瀏覽器(兼容模式/IE 內核)顯示卡住,需新開標籤才渲染出來。
自寫服務器可能缺少以下關鍵響應要素,導致 IE 內核解析阻塞:
\r\n\r\n 缺失或格式錯誤
// 最小完整響應
HTTP/1.1 200 OK\r\n
Content-Type: text/html; charset=utf-8\r\n
Content-Length: 1234\r\n
Connection: close\r\n
\r\n
...body...
HTTP/1.1 200 OK\r\n
Content-Type: text/html; charset=utf-8\r\n
Transfer-Encoding: chunked\r\n
Connection: close\r\n
\r\n
第一塊長度(hex)\r\n
塊內容\r\n
第二塊長度(hex)\r\n
塊內容\r\n
0\r\n // 結束塊
\r\n
curl -v https://localhost:port 查看原始響應頭http/express/koahttp.server/flask/fastapinet/http/gincpp-httplib/crow/pistacheJetty/Undertow/Spring BootChrome (Blink 內核) 容錯性極強,採用投機解析、增量渲染,甚至無 Content-Length 也能按連接關閉判斷結束。IE/360 兼容模式 (Trident/MSHTML) 嚴格遵循 RFC 2616,缺頭等待超時才渲染。
**結論**:補全 HTTP 響應頭(特別是 Content-Length),或直接用成熟框架,問題即刻消失。