December 2017
Intermediate to advanced
498 pages
11h 54m
English
When visiting a URL via a browser, you will often notice a little icon in the browser tab or in the browser's address bar. This icon is an image named favicon.ico, and it is fetched on each request. As such, an HTTP GET request normally combines two requests—one for the favicon, and another for the requested resource.
Node developers are often surprised by this doubled request. Any implementation of an HTTP server must deal with favicon requests. To do so, the server must check the request type and handle it accordingly. The following example demonstrates one method of doing so:
const http = require('http');http.createServer((request, response) => { if(request.url === '/favicon.ico') { response.writeHead(200, { ...
Read now
Unlock full access