Firefox Kept the Old Favicon Even With no-cache: I Reran 8 Favicon Cache Tests in Firefox and WebKit

2026-12-03来源 dev.toEnglish

Last week I tested what Chrome does when you replace a favicon. The short answer was that the icon's URL matters more than its cache header. With a day-long cache, Chrome kept the old icon through reloads, new tabs and restarts. A no-cache header helped on reload. A new URL worked on the next page view.

The obvious follow-up was the other engines. So I took the same test server and the same eight scenarios and ran them in Firefox and in WebKit.

The short version: in Firefox, the cache header on your favicon makes no difference. max-age=86400, no-cache and a 10-second max-age all behaved the same. Firefox drew the old icon from its own copy and never asked the server whether it had changed. Only a hard reload or a new icon URL brought the new one. And that turns out to be deliberate, as you can see in Firefox's own source code.

The setup

The server is the same small Python script as last week. It serves a page that links a solid red 16×16 SVG icon, logs every icon request, and answers conditional requests with a 304 when the ETag matches. Pages themselves are never cached (no-store), so every navigation gets fresh HTML. After the first visit, the server starts serving a blue icon at the same URL, and I do one ordinary thing after another.

What changed this time:

  • Browsers: Playwright's Firefox 153.0 build and Playwright's WebKit 26.5 build, both headful on a virtual X display, each with a persistent profile so the disk cache and the favicon store survive a restart, as in a normal browser.
  • Real key presses. Reload and hard reload are actual F5 and Ctrl+Shift+R key presses sent to the browser window with xdotool, not script calls. I also counted page requests at the server to make sure every reload really happened (each step shows exactly one page load).
  • Reading the tab. Firefox draws a normal tab strip, so after each step I read the colour of the tab icon from a screenshot, as I did for Chrome. Playwright's WebKit build on Linux is a minimal browser with no tabs and no visible favicon, so for WebKit I can only report which icon requests reached the server, not what a user would see.

Two honest caveats before the numbers. Playwright's browsers are patched builds for automation, close to the release versions but not identical. And the WebKit build is not Safari. It shares the engine, but Safari's favicon handling lives partly in the app around the engine, so treat the WebKit column as a hint, not as Safari's behaviour.

The key presses are the only new code:

def key(k): subprocess.run(['xdotool', 'key', k], env=dict(os.environ, DISPLAY=DISPLAY)) def f5(st): def f(): focus(st['p']); key('F5') return f def hard(st): def f(): focus(st['p']); key('ctrl+shift+r') return f 

Each step waits 4 seconds before the screenshot and the request count.

All eight scenarios, three engines

When did the new icon first show up (Chrome, Firefox) or first get requested (WebKit)? The Chrome column is last week's run in real Chrome 156.

Scenario Icon headers Chrome 156 Firefox 153 WebKit 26.5 build (requests only)
A: same URL, day-long cache max-age=86400 hard reload hard reload never, not even on hard reload
B: same URL, revalidate no-cache + ETag first F5 hard reload new tab, hard reload, restart
C: new URL after the change ?v=1 → ?v=2, cached a year first F5 first F5 first F5
D: no <link>, /favicon.ico max-age=86400 hard reload hard reload never
E: day-long cache, only restarts max-age=86400 never (2 restarts) never (2 restarts) never
F: short cache max-age=10, wait 15 s first F5 after expiry never, even after a restart only after a restart
G: revalidate, restart first no-cache + ETag first F5 after restart never never
H: new URL, no reload ?v=1 → ?v=2 next page view next page view next page view

Two rows stand out: F and G. They are the "I set the right header" setups, and in Firefox they did nothing.

Finding 1: in Firefox, the header didn't matter

Here is scenario B in Firefox, the setup most guides recommend if you want changes to show up: Cache-Control: no-cache plus an ETag, so the browser has to ask before reusing its copy.

1 first visit (icon is red) server=red tab=red | /icon.svg 200 -- icon file on the server is now BLUE 2 reload (F5) server=blue tab=red | no icon request 3 click a link to another page server=blue tab=red | no icon request 4 same page in a new tab server=blue tab=red | no icon request 5 hard reload (Ctrl+Shift+R) server=blue tab=blue | /icon.svg 200 [req no-cache] 6 restart browser, open the page again server=blue tab=blue | no icon request 

No request at all until the hard reload, and the hard reload request carried the browser's own no-cache request header. Chrome, in the same scenario, re-checked the icon on the very first F5.

Scenario F is even clearer. The icon was cacheable for only 10 seconds, and I waited 15 seconds twice:

1 first visit (icon is red) server=red tab=red | /icon.svg 200 -- icon file on the server is now BLUE 2 reload right away server=blue tab=red | no icon request 3 wait 15 s, then reload server=blue tab=red | no icon request 4 wait 15 s, click to another page server=blue tab=red | no icon request 5 restart browser, open the page server=blue tab=red | no icon request 

The cached copy had been expired for half a minute, the browser had been restarted, and Firefox still drew the red icon without asking.

Why: Firefox loads favicons with "never validate"

This isn't a bug in the test. Firefox's tab icons are fetched by a small module in the browser itself, FaviconLoader.sys.mjs, and its request setup reads like this (current source on GitHub):

if (iconInfo.isForceReload) { this.channel.loadFlags |= Ci.nsIRequest.LOAD_BACKGROUND | Ci.nsIRequest.LOAD_BYPASS_CACHE; } else { this.channel.loadFlags |= Ci.nsIRequest.LOAD_BACKGROUND | Ci.nsIRequest.VALIDATE_NEVER | Ci.nsIRequest.LOAD_FROM_CACHE; } 

In plain words: on a force reload (Ctrl+Shift+R), skip the cache. Otherwise, take the icon from the cache if there is one and never check whether it is still fresh. That explains every Firefox row in the table. no-cache asks the browser to validate, and the loader says never validate. An expired max-age would normally trigger a new request, and the loader says take it from the cache anyway. Only a cache miss (a URL it has never seen) or a force reload goes to the network.

It's a sensible choice for a browser. Favicons are loaded constantly, and nobody wants a request for every tab on every navigation. But it means a server-side header can't push a changed icon to Firefox users at the same URL.

Finding 2: restarting doesn't help in Firefox either

Scenarios E and G restart the browser twice without a hard reload. In Firefox, both kept the old icon through both restarts. The disk cache survives a restart, and with "never validate", a cached icon stays in use until the cache entry is evicted or the user force-reloads. I didn't test how long eviction takes on a busy profile. That depends on cache size and browsing, so it isn't something you can plan around.

Finding 3: the WebKit build re-checked only in some cases

The WebKit build behaved differently from both. With a day-long cache (A, D, E) it never asked for the icon again, not even on Ctrl+Shift+R. With no-cache (B) it sent a conditional request when a new tab opened, on the hard reload and after a restart, but not on a plain F5. With a 10-second cache (F) it asked again only after a restart.

I ran the whole WebKit set twice, and both runs gave exactly the same requests, so the pattern is stable in this build. I wouldn't generalise it to Safari. Safari's tab icons go through the app, not only the engine, and Safari has its own rules for icon formats. One thing I could check without a Mac: the EmojiFavicons docs say Safari gets a PNG instead of an SVG, and a request with a Safari user agent did come back as image/png with a 24-hour max-age.

Finding 4: a new URL worked everywhere

Scenarios C and H change the icon's URL from /icon.svg?v=1 to /icon.svg?v=2 at the same moment as the file. In all three engines, the next page view requested ?v=2 and (where I could see the tab) drew the blue icon:

-- icon file on the server is now BLUE, page now links /icon.svg?v=2 2 click a link to another page server=blue tab=blue | /icon.svg?v=2 200 3 restart browser, open the first page server=blue tab=blue | no icon request 

That's the same result as in Chrome. A browser that has never seen a URL can't serve it from cache, whatever its rules are. And once the new URL is cached, a year-long max-age is harmless, because the next change gets a new URL too.

I also tried it with real emoji icons. The test page first linked https://emojifavicons.com/rocket, and Firefox showed 🚀 in the tab. Then the page was changed to link https://emojifavicons.com/fire and I pressed F5 once: the tab showed 🔥. Different emoji, different URL, no cache problem.

What to do when you change a favicon

  1. Change the URL whenever you change the icon. A version query (/icon.svg?v=2) or a hashed file name (icon.3f9a1c.svg) from your build tool both work. This was the only approach that worked on the next page view in Chrome, Firefox and the WebKit build.
  2. Always add an explicit <link rel="icon">. A browser that only finds /favicon.ico by convention (scenario D) has no URL you can version. Keep /favicon.ico for old clients, but point the <link> at a versioned file.
  3. Don't rely on no-cache for favicons. It helped in Chrome on reload. In Firefox it didn't help at all, and in the WebKit build only at certain moments.
  4. Use long cache times on versioned URLs. Once the URL changes on every update, max-age=31536000, immutable saves requests and costs nothing.
  5. Checking your own deploy in Firefox: press Ctrl+Shift+R on the page. A normal reload or a restart won't show you the new icon if the URL is the same.
  6. Update every place the icon URL lives: layout templates, the web app manifest, apple-touch-icon tags and any email or docs templates that reference it.

If you use EmojiFavicons, switching to a different emoji, background or shape already changes the URL, so the new icon shows up on the next page view. You can try shapes and backgrounds with a live preview in the generator. If you make your favicon from an image instead, the FindUtils Favicon Generator builds the icon sizes in your browser without uploading the image. Just give the files a new name or version when you replace them.

What this doesn't show

  • Real Safari, Edge or mobile browsers. Edge uses Chromium, so I'd expect Chrome's results, but I didn't test it. Safari needs a real Mac and iPhone.
  • Release builds. Playwright's Firefox and WebKit are patched for automation. The Firefox result matches its source code, which makes me fairly confident, but I didn't repeat it on a stock install.
  • Bookmarks, history and the new-tab page. Firefox also keeps icons in its places database for those. I only looked at the tab.
  • Long-term eviction. I didn't test how many days or how much browsing it takes before Firefox drops a cached icon on its own.

The rule from last week holds, and it's stronger now: if you want people to see a new favicon, give it a new URL. The cache header is a suggestion that at least one major browser ignores for tab icons by design.

For setup instructions by framework, see the EmojiFavicons guide.

Laravel app still showing old assets after a deploy? The team behind FindUtils takes on freelance work on Upwork, including a Laravel bug fix, version upgrade or new feature for your app.

原文:https://www.a8q9.cn/en/article/firefox-kept-the-old-favicon-even-with-no-cache-i-reran-8-favicon-cache-tests-in-066fdb.html

相关文章