Create a Blank Favicon with Data
I was recently setting up a virtual host and diving into development when I needed to debug a JavaScript issue. One thing that started annoying me right away was the console message notifying me that the favicon.ico file couldn't be found. I hadn't put one there and had no desire to...but that damn message was bugging the hell out of me. I did a quick search and found a tiny data URL snippet to include a blank favicon within the page.
The HTML
The empty favicon is created with the LINK element:
<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
Essentially, instead of linking the external ico file, the image data is placed in the HREF attribute. Cool, huh? No more annoying messages and no need to add another file to the repository.
![CSS Animations Between Media Queries]()
CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...
![Write Simple, Elegant and Maintainable Media Queries with Sass]()
I spent a few months experimenting with different approaches for writing simple, elegant and maintainable media queries with Sass. Each solution had something that I really liked, but I couldn't find one that covered everything I needed to do, so I ventured into creating my...
![MooTools 1.2 Tooltips: Customize Your Tips]()
I've never met a person that is "ehhhh" about XHTML/javascript tooltips; people seem to love them or hate them. I'm on the love side of things. Tooltips give you a bit more information about something than just the element itself (usually...
![Do / Undo Functionality with MooTools]()
We all know that do/undo functionality is a God send for word processing apps. I've used those terms so often that I think of JavaScript actions in terms of "do" an "undo." I've put together a proof of concept Do/Undo class with MooTools.
The MooTools...
The exact same thing annoyed me in the exact same environment, thanks for the heads up Dave :)
Hi david,
Favicon is the thing which people generally forgot to add in site and they got very massive 404 error for that, which is not shown to user but affect the site loading time, Thanks for easy and quick solution…
Avinash
It’s also probably worth noting this could be used for making dynamic icons without saving data to your host. Like a pretty graphic that displays the user’s name? Just throw the href attribute into the src attribute of a image tag.
IE6 is the only browser I have found this not to work on.
Yeah dude, that would be awesome.
Thats pretty cool, i’ve seen the base64 images like that before, does anyone know the full browser compatibility for using that?
This is the best solution, no more calls to /favicon.icon!
The W3C Validator uses this technique, too, to show if the site is valid or not in the URL bar.
http://validator.w3.org/check?uri=http%3A%2F%2Fjanbuschtoens.de%2F
Did you use any converter to turn your favicon into a long base64 string?
Thanks!
<?PHP
echo base64_encode(file_get_contents('favicon.ico'));
Even better!
I’m pretty sure Data URIs don’t work in IE7.
http://stackoverflow.com/questions/1765342/which-browsers-support-data-uris-and-since-which-version
However, now that IE9 is out, SCREW IE7!
And IE6 has been dead to me for nigh on 3 years. Except where I’m currently working. : (
Thanks a lot :), have a nice day sir!
I’d really like to hear more about that… is it possible to change the favicon using JavaScript while the page is loaded? That would be neat for WebApplications stuck in an unopened tab to notify the user that something has happened, for instance with aninstant messenging thingy.
I think it’s only supported in FF and Opera, but here’s a nice post on changing favicons dynamically.
http://softwareas.com/dynamic-favicons
(and a demo)
http://ajaxify.com/run/favicon/
Surely that should be “debugging the hell out of me”?
Sorry… couldn’t resist!
:-)
Nice! :)
Beware of Internet Explorer!!!
As someone have said, this doesn’t work in IE6 or 7. In IE8 and above works.
Nevertheless there are solutions to integrate images this way with MHTML
http://www.phpied.com/mhtml-when-you-need-data-uris-in-ie7-and-under/
Interesting article! Do you know about setting base64 favicons globally with .htaccess? My website is configured to include the favicon regardless of what file you’re viewing, including images, CSS, and JavaScript files.
thanks a lot dude. i manage to change my favicon with this tutorial.
With GIF it’s even smaller:
data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw
(IE ≥ 11)