訪問WEB首頁時,每個請求會發送2次請求到後臺的原因
發現首頁被請求了2次,後來經過除錯後發現HTML中有這麼一段:
當img標籤中src屬性為一個空字串時會產生這個多出來的請求!!
產生此問題的HTML:
straight HTML
<img src="">
JavaScript
var img = new Image();
img.src = "";
產生結果如下:
Internet Explorer makes a request to the directory in which the page is located. 按當前請求目錄請求一次,如訪問 http://192.168.3.170:81/fuzhou/index.html 則請求http://192.168.3.170:81/fuzhou/
Safari and Chrome make a request to the actual page itself. 按當前請求地址在請求一次
Firefox 3 and earlier versions behave the same as Safari and Chrome, but version 3.5 addressed this issue[bug 444931] and no longer sends a request. 同上
Opera does not do anything when an empty image src is encountered. 不會請求
分享下原文出處,參考: Yahoo's Best Practices for Speeding Up Your Web Site(http://developer.yahoo.com/performance/rules.html), Avoid Empty Image src
同事的總結,記錄一下!很好!