問題描述
這可能只是突出了我的一些誤解,但我很好奇:
This may just highlight some misconception of mine, but I was curious:
如果您正在運行 HTTP/2 服務器并希望在瀏覽器中向服務器發出 XHR 請求,XHR 會自動利用標頭中的性能優化以及它提供的性能優化嗎?
If you had an HTTP/2 server running and wanted to make XHR requests in the browser to the server, would XHR automatically take advantage of the performance optimisations in headers and such that it provides?
還是會忽略該功能并作為 HTTP 請求運行?如果是這樣,我們可以做些什么來在我們的請求中使用新的優化?
Or would it ignore that functionality and operate as an HTTP request? If so, are there any things we can do to use the new optimisations in our requests?
推薦答案
你不需要做任何事情.如果服務器支持 HTTP/2,XHR 將使用它.標頭壓縮等會自動啟動.
You don't need to do anything. If the server supports HTTP/2, XHR will use it. Header compression and such will kick in automatically.
測試一下:
- 在 Chrome 中打開一個 HTTP/2 網站.您可以使用我們的 來查看一些關于 HTTP/2 PUSH、AngularJS 和 RequireJS 的酷東西.
- 打開 Devtools 面板 (F12),然后打開網絡面板,然后單擊 XHR.右鍵單擊標題行,并確保您擁有協議";列已啟用.
- 您應該會看到h2";在上述列中(在我們的例子中,AngularJS 正在通過 XHR 加載模板).
- 此時,請注意服務器推送了 XHR 請求.推送響應的標志是臨時標頭".而不是請求標頭,以及異常小的下載"和等待"次.我們甚至在響應中添加了一個額外的標題 (x-shimmmercat-note:pushed-stream) .瀏覽器采用了這個請求,因此XHR 請求不僅會使用 HTTP/2(如果可用),而且在某些情況下可以使用推送資源.
這篇關于當前的 XHR 實現是否利用了 HTTP/2?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!