Scheduled broken-link and redirect checks that tell you the moment a link breaks — linkbruno.com
You click a link, the page loads, you ship. A week later a user on a fresh phone, a Slack unfurl, or a search crawler gets a 404. The URL was never fine. Your browser was fine, because a service worker, a cached 302, or a precached copy of last week's app.9f3a1c.js answered first.
HTML link checkers do not run your service worker. Neither does curl. That is actually useful: it is the cold-request view. The trick is to compare it with what a warm browser does, and to fail the URL if the two disagree.
Prove the split: curl vs a warm tab
For a URL you are suspicious of:
# a cold request: no cookies, no service worker, no disk cache
curl -sS -D- -o /dev/null -L --max-time 20 \
-H "Cache-Control: no-cache" \
-H "Pragma: no-cache" \
https://example.com/app.js
Look at the status, cache-control, cf-cache-status / x-cache, and the final URL after -L. A 404 or 410 here is the truth for a new visitor, a crawler, and most preview bots.
Then open the same URL in the browser you have been using for days, with DevTools open on the Network panel. If the row says (from ServiceWorker) or (from disk cache) and the status is 200, you have the split. In the Application panel, check Service Workers and Cache Storage: a Workbox precache, a cache.addAll list, or a navigation-route fallback is usually holding the old file.
A redirect can lie the same way. A 301 or 302 that you already followed last week can be reused from the browser's redirect cache even after the server no longer issues it, or after the target has moved again. curl -I (no -L first, then with -L) against the origin is the cold view; the warm tab may never re-ask the server.
Check a list of URLs both ways
curl over a sitemap or a crawl is the cold side. For the warm side, drive a real browser, once with service workers allowed and a populated cache, and once with them blocked.
import sys
from playwright.sync_api import sync_playwright
UA = "cold-vs-warm-link-check/1.0"
URLS = [line.strip() for line in sys.stdin if line.strip()]
def statuses(context, urls):
page = context.new_page()
out = {}
for url in urls:
status = None
def on_response(resp):
nonlocal status
if resp.url == url or resp.request.is_navigation_request():
status = resp.status
page.on("response", on_response)
try:
page.goto(url, wait_until="domcontentloaded", timeout=20_000)
out[url] = status or 0
except Exception as e:
out[url] = f"ERR:{type(e).__name__}"
page.remove_listener("response", on_response)
page.close()
return out
with sync_playwright() as p:
browser = p.chromium.launch()
# Warm: visit once so a service worker can install, then visit again.
warm_ctx = browser.new_context(user_agent=UA)
statuses(warm_ctx, URLS)
warm = statuses(warm_ctx, URLS)
# Cold: no service workers, empty cache.
cold_ctx = browser.new_context(
user_agent=UA, service_workers="block"
)
cold = statuses(cold_ctx, URLS)
warm_ctx.close()
cold_ctx.close()
browser.close()
for url in URLS:
w, c = warm[url], cold[url]
if w != c:
print(f"SPLIT\twarm={w}\tcold={c}\t{url}")
service_workers="block" is the important line. The first pass through warm_ctx is only there to let a worker install; the numbers you compare are the second warm pass and the cold pass. Anything in SPLIT is a URL you cannot trust a visual check for.
You can add a third column from curl -o /dev/null -sS -w "%{http_code}" if you also want "what a non-browser client sees". Browsers and curl can still disagree on header-driven redirects or on HTTP/2 vs HTTP/1.1; treat a curl 404 as broken even if both Playwright contexts were 200 because of some other cache.
What usually causes it
A service worker precache of hashed assets. You renamed app.9f3a1c.js to app.c41e02.js, the HTML on the origin points at the new file, and the worker still serves the old HTML or the old file from Cache Storage. Users who already have the worker load the app; everyone else 404s on the old name, or — worse — old users keep running a client that calls a retired API.
A navigation fallback. Some workers map any unknown path to offline.html or to index.html with a 200. The warm browser shows a page (sometimes a confusing home page). The cold request is a real 404. This also hides broken internal links from anyone testing by clicking around their already-open app.
A cached redirect. You moved /docs to /help and later moved it again. A 301 from the first move is still in the browser. Cold clients follow whatever the server now says, which may be a 404 if you deleted the first redirect.
CDN or browser disk cache of a 200 that is now a 404. Less common with short max-age on HTML, very common on hashed assets and on "forever" font or image URLs that were not actually immutable.
If a URL only works in the tab you have had open all week, it is already broken for someone. linkbruno.com checks links on a schedule, with a cold HTTP request, so a path that a service worker is still covering at your desk shows up as a 404 when it actually is one.
What to do when you find a split
Fix the origin first: restore the file, add a redirect from the old hashed name, or stop advertising the old URL in HTML and in the worker manifest. Then bump the service worker so the precache drops entries that are not in the new list. Workbox and most generate-SW setups will do this if the new worker is actually installed; they will not if you never change the worker file.
For checks in CI, prefer a cold client (curl, a link checker, Playwright with service_workers="block"). Use a warm browser pass as an extra signal, not as the only one. And when you test a fix yourself, use a private window, or unregister the worker and clear Cache Storage, or you will "confirm" a fix that you have not shipped to a new user.
Related reading
- How to fix 404 on refresh in a single-page app (React Router, Vue Router, Angular) on Nginx, Netlify, Vercel, S3 and GitHub Pages
- How to find redirect chains and redirect loops with a short Python script (and why a 200 at the end can still be a problem)
- Soft 404s: your 'page not found' returns 200, and your link checker thinks it's fine
- Should leftover http:// links on an HTTPS site fail the build, or should the checker auto-upgrade them? Let's argue about it
Have you shipped a 404 that only showed up for new users? Was it a service worker, a cached redirect, or something else sitting in front of the origin?
Top comments (0)