dragn
dragn

Reputation: 1050

Adding favicon through a http header

Let's assume that I want to add a favicon on a dynamically generated page (specifically an ADF Faces page, but this is irrelevant). I can't modify a tag of my resulted html. So I try to add a http-header in servlet header. I want my header to be identical to html head element:

<link rel="shortcut icon" href="http://foo.com/favicon.ico">

I'm adding it this way:

httpResponse.addHeader("Link", "<http://foo.com/favicon.ico>; rel=\"shortcut icon\"");

And in my browser I see this header in response:

Link: <http://foo.com/favicon.ico>; rel="shortcut icon"

But, unfortunately, this does not have any effect in IE or Chrome. Anyone tried to achieve the same thing? Am I doing something wrong? Is that should work at all?

Upvotes: 9

Views: 13789

Answers (3)

user257319
user257319

Reputation:

Yeah yeah "draft"..

anyway..

If you want to see how you can use it in-Practice, here is an example (taken from icompile.eladkarako.com)

<ifModule mod_headers.c>
  Header set Link <http://icompile.eladkarako.com/favicon.ico>; REL="shortcut icon"; TYPE="image/x-icon"
  Header set Link <http://icompile.eladkarako.com/favicon.ico>; REL="icon"; TYPE="image/x-icon"
  Header set Link <http://icompile.eladkarako.com/img/apple-touch-icon.png>; REL="apple-touch-icon"; TYPE="image/png"; sizes="316x316"
</ifModule>

It will work in current Chromium/Google Chrome/Google Canary,

(and for sure if you set the switch for advance web-features in chrome://flags)

Upvotes: -1

nickl-
nickl-

Reputation: 8731

Yes Link headers have been a defined standard in RFC 5988 since October 2010 but the only link relation I've seen working are for stylesheet and only in some browsers at that.

Also see: HTTP Header Stylesheets

What @dragn is suggesting is perfectly viable, and in spec why the browsers aren't adopting is beyond me. There are some other useful relations like prefetch, bookmark and glossary to name a few. The least they could do is notify the user that links exist and provide it as a drop down or menu. Maybe a plugin is what is called for to show the browser vendors what we want it to do as it seems they are all confused. Any suggestions?

For now I guess we have to wait till 2020 for this feature to become available which seems to be the trent.

Upvotes: 4

dragn
dragn

Reputation: 1050

And the answer is: this method relies on proposed standard (a draft) that is not implemented yet (thanks to Salman A for pointing this out). Though it would be great if it worked.

Upvotes: 4

Related Questions