Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Favicon not changing in vue cli project

Tags:

vue.js

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="icon" href="<%= BASE_URL %>favicon.ico">
  <title>Vue Router Practice</title>
</head>

<body>
  <noscript>
    <strong>We're sorry but vue-todo doesn't work properly without JavaScript enabled. Please enable it to
      continue.</strong>
  </noscript>
  <div id="app"></div>
  <!-- built files will be auto injected -->
</body>

</html>

This is the code of my index.html file in the public folder. There is also an icon file named favicon.ico. But when I run my dev server, the favicon is not showed. Please help me.

I have tried to change <link rel="icon" href="<%= BASE_URL %>favicon.ico"> to <link rel="icon" href="/favicon.ico"> but it's not working either. and when i type localhost:8080/favicon.ico, it is showing my favicon.

Also, there are correct HTML tags when I debug on chrome dev tool.


<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="icon" href="<%= BASE_URL %>favicon.ico">
  <title>Vue Router Practice</title>
</head>

Expected result: favicon should be shown.

like image 681
Derek Jin Avatar asked Aug 29 '19 11:08

Derek Jin


People also ask

Why is favicon not working?

When you add a favicon to your site, it may not show up since your browser has 'saved' your site as one without a favicon. You need to clear the cache in your browser or use a different browser.

Does vue CLI support vue 3?

Vue CLI is now in maintenance mode. For new projects, please use create-vue to scaffold Vite-based projects. create-vue supports both Vue 2 and Vue 3.


3 Answers

I have a same problem.. but I success to fix this, when I switch the double quote to simple quote in the attribute rel, but I don't know why..

    <link rel="icon" href="<%= BASE_URL %>favicon.ico">

replace with:

    <link rel='icon' href="<%= BASE_URL %>favicon.ico">
like image 166
bensbenj Avatar answered Oct 17 '22 05:10

bensbenj


If you're using PWA, check your public/img/icons folder too. And make sure that your favicon-16x16.png and favicon-32x32.png files are not the default ones.

And also best way to force cache is to hit the favicon address directly

http://yourwebsite.com/favicon.ico

and press control+f5 for windows/linux or shift+command+R for Mac. You will see it changes. Then navigate back to your webpage and it will be refreshed.

like image 20
Cüneyt Aliustaoğlu Avatar answered Oct 17 '22 03:10

Cüneyt Aliustaoğlu


I had this issue and it seemed that Chrome was caching the favicon (was working on multiple projects at once). So a clear of the cache and closing the browser tab and restart is what worked for me

like image 2
Thomas M Avatar answered Oct 17 '22 05:10

Thomas M