Firefox首次加载页面时发送三重请求

时间:2014-05-26 14:51:51

标签: node.js firefox request response

我是NodeJS的新手。 我正在练习下面的示例代码。

var http = require('http');
var count = 0;
http.createServer(function(request,response){
        console.log("request hit "+ ++count);
        response.writeHeader(200,{"content-type":"text/plain"});
        response.write("Hello World");
        console.log("Request served", count);
        response.end();
    }).listen(8050);
console.log("Server running on 8050");

第一次点击的Firefox中的输出。

request hit 1
Request served 1
request hit 2
Request served 2
request hit 3
Request served 3

重新加载页面时,Firefox会收到单个响应。

有谁能告诉我它的原因?

4 个答案:

答案 0 :(得分:1)

我的猜测是第一次请求,firefox将获取该页面。下一个请求firefox将获得favicon.ico。下次刷新页面时,firefox已经缓存favicon.ico并且它不会再次请求它,所以它只会获取页面。

答案 1 :(得分:0)

第二个请求可能是GET /favicon.ico。第三个可以由一些插件启动。您可以通过打印request.methodrequest.url来解决这个问题。

答案 2 :(得分:0)

如果你看一下网址......

server running on 8085>
Count: 1
GET
/
Count: 2
GET
/favicon.ico
Count: 3
GET
/favicon.ico

所以seens就像firefox要求/favicon.ico两次,在第二个请求中firefox已经缓存了这个url。

google chrome中的行为类似,但chrome只为get /和get /favicon.ico做了一次请求,因此在chrome中你有2个请求。

有趣的是为什么firefox正在为favicon.ico做2次请求,如果对/favico.icon的第一次请求失败,请再试一次。

似乎是一个已知问题issue

答案 3 :(得分:0)

谢谢大家。通过这些答案,我将包括我找到的那个。

Firefox发送两个favicon请求。原因是,Firefox功能也是考虑Chrome浏览器的favicon。

我在firefox的“about.config”页面中找到了这个。在那个页面中,我可以看到“browser.chrome.favicons”和“browse.shell.shortcutsFavicons”。在禁用两个favicons时,我现在只能获得一个请求。

相关问题