雅虎的YSlow外掛程式的規則之一:Rule 9 – Reduce DNS Lookups提到:
Reducing the number of unique hostnames has the potential to reduce the amount of parallel downloading that takes place in the page. Avoiding DNS lookups cuts response times, but reducing parallel downloads may increase response times. My guideline is to split these components across at least two but no more than four hostnames. This results in a good compromise between reducing DNS lookups and allowing a high degree of parallel downloads.
說說自己的理解:
首先,一個頁面所需要訪問的網域名稱數量為n,那麼就需要n次DNS尋找,而DNS尋找通常是blocking call,就是說在得到結果之後才能繼續,所以越多的DNS尋找,反應速度就越慢;
其次,並行下載(parallel downloading)由兩個因素決定:到伺服器的串連數量,以及每個串連內部的流水線請求數量。
一個頁面裡到伺服器的串連數量由兩個因素決定:
頁面所需訪問的網域名稱數量,和
瀏覽器所允許的最多串連數
後者在Mozilla/Firefox中還由瀏覽器所允許最多串連數(network.http.max-connections,預設為24),和每個伺服器所允許的最大串連數(network.http.max-connections-per-server,預設為8)決定。如果max-connection-per-server是m,那麼一個需要訪問n個不同網域名稱的主機的頁面,最多可以有n*m個串連 - 前提是n*m小於max-connections的值;
每個串連內部的流水線請求(pipelined requests)的數量也是瀏覽器的參數(Firefox上由network.http.pipelining來設定,預設為4),前提是伺服器支援persistent connection(比如在Apache設定KeepAlive為On)。之前的例子就不需要那麼多的串連了(對伺服器和瀏覽器來說,一個串連裡多個流水線請求能夠比多個並行串連更好些),假設pipelining的值為p,那麼就可以只使用n*m/p個串連了。(BTW,對Firefox做最佳化的一些外掛程式其實就是對上面的幾個設定做調整)
所以減少頁面內不同hostname的數量不一定會減少並行下載的數量,也要看所需要的請求(css, javascript, 圖片等)的數量,因此YSlow的解釋說是potentially。