Reputation: 167
I am running a barebones Nodejs server only using the HTTP module. I've created an HTTP server and am listening on socket connections and on requests. I noticed that when I use chrome and go to localhost, three sockets connect, and two requests are made to "/". I know that, using some other webservers, I've seen Chrome request the same thing multiple times if it does not receive a quick response (about 5 seconds), but I am sending a response right away and still Chrome is connecting/requesting multiple times.
Is this expected, and if it is, should I be expected to handle duplicate requests?
My relevant code
let server = http.createServer();
server.listen({
host: host,
port: port
});
server.on('connection', function(socket){
// gets printed 3 times
console.log('connection')
});
server.on('request', function(request, response){
// gets printed two times
console.log('hi')
// yet chrome only receives one response (seemingly)
response.end('hi')
});
Edit: Half solved. Now I am printing request.url
and I see
/
and
favicon.ico
So there are 2 requests, but still 3 socket connections. I guess every single request is on a new socket?
Upvotes: 0
Views: 278
Reputation: 1
It typically makes 2 request and one preconnection
GET /
GET /favicon.ico
The third request has a time out of 1 min
I observed this behavior when I was building my own http server in c++
Upvotes: 0
Reputation: 3619
All individual images, css and javascript will definitely make http requests. No doubt about it.
Upvotes: 1