首页 > chrome打开一个页面为什么会有两次请求?

chrome打开一个页面为什么会有两次请求?

首先,我运行了这个简单的例子。

// server.js

'use strict';

const http = require('http');

http.createServer((req, res) => {
  console.log('Request received.');
  res.writeHead(200, {
    'Content-Type': 'text-plain',
  });
  res.write('Hello World');
  res.end();
}).listen(8888);

console.log('Server has started.');

然后,在chrome打开了localhost:8888页面。控制台显示:

Server has started.
Request received.
Request received.

而在firefox中有时显示1次Request received.,有时3次。
为什么浏览器会发出多次的请求?


一般情况下,会请求一次 document 和一次 favicon,其他的得看内容。


favicon 这个无疑。。碰到好多次。。


F12 - network 里面有请求内容


你在chrome控制台看一下请求的资源就明白了


静态资源有请求吧,比如网页小图标

【热门文章】
【热门文章】