无法使用 Express.js 更改网站图标 [英] Unable to Change Favicon with Express.js

查看:48
本文介绍了无法使用 Express.js 更改网站图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常基本的问题,但我正在尝试使用

This is a really basic question, but I'm trying to change the favicon of my node.js/Express app with

app.use(express.favicon(__dirname + '/public/images/favicon.ico'));

而且我仍然得到默认的图标.这是在我的 app.configure 函数中,是的,我已经验证 is/中有一个 favicon.icopublic/images/favicon.ico.控制台中也没有关于 favicon.ico 的内容,这让我相信这行代码被忽略了.函数中的其他所有内容(设置端口、设置视图目录、设置模板引擎等)似乎都运行良好,那么为什么这行代码没有执行?

and I'm still getting the default favicon. This is in my app.configure function, and yes, I've verified that there is a favicon.ico in the /public/images/favicon.ico.There's nothing about a favicon.ico in the console, either, which leads me to believe that this line of code is being ignored. Everything else in the function (setting port, setting views directory, setting template engine. etc.) seems to be working fine, so why would this line of code not be executing?

我尝试了什么

  • 清空浏览器缓存
  • 重新启动终端并再次运行 node app.js
  • 添加 { maxAge: 2592000000 },如这里

提前致谢.

更新:我让它工作了.有关详细信息,请参阅下面我的回答.

Update: I got it to work. See my answer below for more information.

推荐答案

我第一次尝试在 Safari 中访问该站点(我通常使用 Chrome)并注意到它显示了正确的 favicon.我再次尝试清除 Chrome 中的缓存(两次)但无济于事,但经过更多搜索,我发现 显然图标没有存储在缓存中.我使用 此处 描述的方法刷新了我的收藏夹图标",并且成功了!

I tried visiting the site in Safari for the first time (I normally use Chrome) and noticed that it was showing the correct favicon. I tried clearing my cache in Chrome again (twice) to no avail, but after more searching, I found that apparently favicons aren't stored in the cache. I "refreshed my favicon" using the method described here and it worked!

这里是方法(从上面的链接修改),以防链接失效:

Here's the method (modified from the above link), in case the link goes dead:

  1. 打开 Chrome/有问题的浏览器
  2. 直接导航到 favicon.ico 文件,例如http://localhost:3000/favicon.ico
  3. 按 F5 或相应的浏览器刷新(重新加载)按钮刷新 favicon.ico URL
  4. 关闭浏览器并打开您的网站 - 瞧,您的收藏夹图标已更新!

这篇关于无法使用 Express.js 更改网站图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆