6

Am I missing something? Here is what I have:

var express = require('express');
var favicon = require('serve-favicon');
var path = require('path');

var app = express();

app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 

app.use('/api', require('./routes/api'));

app.listen(3000);

My favicon is located as specified in the public folder and the same name. I have some other routes setup separately in a file. The favicon doesn't appear to be working, I must be missing something.

Baba Zannah
  • 316
  • 1
  • 3
  • 14
  • what does the developer console log in browser ?! – Gntem Apr 13 '17 at 21:26
  • It doesn't show up anything mate, it looks as though everything appears to be working fine, only that the favicon doesn't show. Thanks. – Baba Zannah Apr 13 '17 at 21:29
  • Look at the network tag in the Chrome debugger when your page loads and see if the browser is actually requesting the favicon.ico file from your server. If so, see what response it is getting back. – jfriend00 Apr 13 '17 at 21:39
  • @jfriend00 I did that, it is not requesting the favicon. It's completely not there. What could that be? Thanks mate. – Baba Zannah Apr 13 '17 at 21:49
  • What's in the `` section of the HTML document that might be favicon relevant? It is possible for a web page to tell a browser NOT to request a favicon. Or, conversely, you can specifically reference a favicon: http://stackoverflow.com/questions/11893478/add-favicon-to-website or http://stackoverflow.com/questions/10218178/necessary-to-add-link-tag-for-favicon-ico – jfriend00 Apr 13 '17 at 21:56

4 Answers4

11

The browser might have cached an older favicon. You can force the browser to refresh the cache by adding a version to the new favicon like so:

<link rel="icon" href="favicon.ico?v=1.1">
moeabdol
  • 4,779
  • 6
  • 44
  • 43
10

This answers your question.

It says:

  1. Go to http://localhost:3000/favicon.ico
  2. Refresh the page.
  3. Restart the browser.
Gaurish Gangwar
  • 395
  • 4
  • 14
3

Check what is in the <head> section of the document. While a browser may implement a default favicon.ico behavior, it can also be controlled from the <head> section by either telling the browser what file/path you want it to fetch the favicon from, what type of file it is or that you don't want it to look for a favicon at all.

Here are two other references on the topic that cover some of the specifics:

Add Favicon to Website

Necessary to add link tag for favicon.ico?

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
2

Chrome cached that there is no favicon. The favicon will show in production.

skiilaa
  • 1,212
  • 11
  • 20