Sunday, October 01, 2006

Favicon caching in Firefox

Should you google favicons, you will find statements like: when a browser first visits a site, the browser will request the file favicon.ico from a site's root folder. It's a bit more involved than this for Firefox. Firefox allows both webpage favicons for individual pages and a site favicon for all pages within a web domain. Firefox favicon processing looks like this for pages with content type text/html:


if a page has a favicon link then
if the requested webpage favicon is not cached then
try:
request the webpage favicon from the web server
if the webpage favicon is served then
cache the webpage favicon
else
webpage favicon = default favicon
catch:
webpage favicon = default favicon
else
webpage favicon = cached webpage favicon

try:
load the webpage favicon
catch:
load the default favicon

else
if the website favicon is not cached then
try:
request the website favicon from the web server
if the website favicon is served then
cache the website favicon
else
cache the default favicon as the website favicon
catch:
cache the default favicon as the website favicon

try:
load the cached website favicon
catch:
cache the default favicon as the website favicon
load the cached website favicon


Note: I used the nifty Firefox extension Tamper Data to look at communications between Firefox and an IIS 5.1 server. Tamper Data is much more convenient than inspecting browser requests in server logs.



Observations


  • Firefox caches webpage favicons and website favicons in the same cache that is reached by Tools»Options»Privacy»Cache. Firefox appears also to keep a copy of its default favicon in this cache. (Bookmark favicons are saved with the bookmarks themselves in a file named bookmarks.html, which is kept separately for each user.)


  • A webpage favicon and a website favicon are mutually exlusive for any given page. If a favicon link is present in a page, no attempt will be made to obtain or load a website favicon.


  • A first visit to a web domain is signalled by the absence of a cached website favicon. A page containing a favicon link causes a webpage favicon to be cached, but has no effect on the presence or absence of a cached website favicon. Thus Firefox will continue to look forward to its first visit to a domain while rendering any number of pages with favicon links retrieved from that site. Firefox seeks a website favicon only when (1) it receives a page that does not have a favicon link and (2) discovers no cached website favicon for the web domain of that page. Given a cleared cache, this dual state will be reached exactly once for any web domain.


  • The only way to cause Firefox to change a website favicon is to clear this cache. Once a website favicon is cached, whether one actually obtained from a server or a copy of the default favicon, Firefox will not request that website favicon again.


  • Firefox keeps every successfully-loaded webpage favicon in the cache. More than one webpage favicon may be cached for a page. More than one page may be associated with any webpage favicon in the cache.


  • In contrast to website favicons, default favicons are not cached as webpage favicons. Firefox will continue to request a webpage favicon each time a page is served until the requested webpage favicon is successfully loaded. Thus, an initial default webpage favicon may change to a specified webpage favicon. Once a specified webpage favicon has been cached, Firefox will not request that webpage favicon again, and a successfully-loaded webpage favicon can not be reverted to the default favicon.


  • The webpage favicon for a page can be changed by specifying a different favicon image file in the page's favicon link before the page is rendered again. However, the content of a specified webpage favicon can not be changed once it is cached. The cache must be cleared to change the content of any cached webpage favicon.


  • Firefox will not bypass the cache for favicons.

    • Note that this contrasts sharply with the way Firefox treats images rendered in pages (i.e., in the viewport). When a page is reloaded, Firefox will ask whether an image has been changed and if it has changed, Firefox will load the updated image from the server rather than load the locally cached image. Bypassing the cache will force Firefox to replace cached viewport images with new images from the server.

    • Due to this difference in handling favicon images and viewport images, it is possible for Firefox to display a different image for a favicon than it does for a viewport image rendered from ostensibly the same image file. In this case, the favicon image will be previous version of the content of the image file.


  • Firefox’ browsing history is not at all involved in this.


0 Comments:

Post a Comment

<< Home