Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve a unique favicon.ico per project #62

Closed
billiegoose opened this issue Mar 11, 2017 · 12 comments
Closed

Serve a unique favicon.ico per project #62

billiegoose opened this issue Mar 11, 2017 · 12 comments
Assignees

Comments

@billiegoose
Copy link
Member

Browser's tend to cache the favicon, and so whenever I start a new project and am serving on http://localhost:3000 it will use the icon from some other project I'm working on. What's more, Chrome will add 404 errors for favicon.ico to the network request log and the console, and my heart rate goes up whenever Chrome starts printing red text in the console. This is one of those little bitty irksome things that bothers me just enough over time that I am resolved that jus serve be able to invent a new favicon.ico on the fly and serve it for projects that don't have a favicon.

My plan is to use identicon to generate the favicons, and then make an express middleware that can plugged into jus. This page shows examples what identicons look like:
image

@billiegoose
Copy link
Member Author

No code to merge yet, because I like being able to install jus and so we can't add 'identicon' as a dependency yet. But when we do, my code looks something like this:

// lib/server.js
const express  = require('express')
const cors     = require('cors')
...
const identicon = require('identicon')
const favicon   = require('serve-favicon')

var server = module.exports = express()
server.use(cors())

// Create unique favicon from the current working directory
var faviconPNG = identicon.generateSync({id: process.cwd(), size: 16})
server.use(favicon(faviconPNG))
...

@jdormit
Copy link
Member

jdormit commented Mar 12, 2017

Looks good, but is there a check to serve an existing favicon if one exists?

@billiegoose
Copy link
Member Author

Right, obviously an actual favicon.ico would take priority. I suppose that would mean putting server.use(favicon(faviconPNG)) farther down, as a fallback for the static server.

@zeke
Copy link
Member

zeke commented Mar 12, 2017

So this is just for development? Or do you also intend to kick out a default favicon in the build process if none exists?

@billiegoose
Copy link
Member Author

I was just thinking of during development, to help me keep my tabs straight. Do you think people would want a defacto favicon in the built version?

@zeke
Copy link
Member

zeke commented Mar 13, 2017

Do you think people would want a defacto favicon in the built version?

Probably not. Just clarifying your intent. :)

@billiegoose
Copy link
Member Author

Oh boy! My identicon PR already is merged and on npm! :)

@billiegoose
Copy link
Member Author

billiegoose commented Mar 14, 2017

How seriously do we take IE support? Apparently some browser STILL doesn't accept PNG favicons. There's a to-ico module that can convert a PNG buffer to an ICO buffer, but it'll drag in a bunch more dependencies.

Edit: Correction! I have maligned IE unjustly. It does take PNG favicons. It is just very VERY stubborn about caching favicons. (Had to delete the browser history to uncache them.)

@billiegoose
Copy link
Member Author

billiegoose commented Mar 14, 2017

Edit: Ignore my original grumpy old man statement. Feel free to discuss the feature / concept in this thread and critique the implementation in the pull request. Apparently in the grand scale of things that is supposed to make life less confusing.

(grump grump grump) Is there not a way to turn an existing issue into a pull request? I feel like the discussion should move to the pull request #63 but it's annoying that it's gonna fragment the conversation thread by doing that.

@zeke
Copy link
Member

zeke commented Mar 14, 2017

Is there not a way to turn an existing issue into a pull request?

Pretty sure you can still do it with https://hub.github.com/

@billiegoose
Copy link
Member Author

Oh my. Googling that led to some loooong discussion threads. It sounds like the recommended practice is to separate concerns: issues for the bug / feature itself, pull-requests for the implementation details. Now I know, let's go with the flow. :)

jdormit added a commit that referenced this issue Mar 16, 2017
Serve a unique favicon per project! Solves issue #62
@jdormit
Copy link
Member

jdormit commented Mar 16, 2017

Merged in #63

@jdormit jdormit closed this as completed Mar 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants