DEV Community

Zero 404s Across 1,001 Static Pages: An Internal-Link Audit That Actually Scales

In my last post I wrote about shipping a ~850-page static catalogue site on Cloudflare Workers. This one is about what happened two weeks later, when we finally audited the internal link graph and found out how much of it was quietly broken.

The site is our fabric catalogue - mujiatextile.com runs 1,001 static pages: 822 long-form articles in six languages plus 179 root-level pages, all static HTML deployed to a Workers assets bucket. Every page links to dozens of others: nav, footer, related products, localized siblings - it works out to about 130 internal links per page, 131,832 link references in total.

We now have a CI-style audit that keeps the broken-link count at zero. Here's the setup, because the naive version doesn't scale.

The naive version dies at scale

The obvious approach: wget --spider or a crawler that fetches every internal URL and reports non-200s. It works on 50 pages. On 1,001 pages across six languages it falls over in boring ways:

  • It's slow enough that nobody runs it. Twenty minutes of sequential fetches means the audit runs "when someone remembers," which means never.
  • It produces flaky failures. A CDN edge hiccup becomes a red line in the report; people learn to ignore red lines; the report becomes wallpaper.
  • It tests the deployed site, not the commit. You find out about a broken link after it's live.

We wanted: fast, deterministic, and runnable against the working tree before deploy.

What actually worked: audit the graph, not the HTTP

The key realization: for a static site, a broken internal link is a file system fact, not a network fact. If page A links to /es-products.html, the question "does that resolve" is answered by the repo, not by a server.

So the audit is a build-time script:

  • Parse every HTML file, extract href / src values that are internal (start with / or same-origin).
  • Normalize: strip fragments, strip query strings, resolve relative paths, map / to index.html.
  • Check each target against the file tree.
  • Report anything that doesn't resolve.

No network. The whole run takes seconds, so it runs on every meaningful change. Deterministic: same tree, same result, no flakes.

The edge cases that mattered

The simple version of that script still lies to you. The cases that bit us:

Language-prefixed mirrors. ar-catalog.html and catalog.html are different files; a relative href="catalog.html" inside /fr-products.html means the root catalog.html, not fr-catalog.html. Your resolver has to match your deploy layout exactly - in our case everything is flat at the root, so relative links escape the language "namespace." That's a feature, but the auditor must model it.

Pages that exist but must not be linked. We keep redirect stubs around for renamed URLs - little shells with noindex and a meta refresh. A link to a stub resolves fine and passes a naive check, but it's still wrong: you're sending users through a redirect for no reason. The audit treats "internal link whose target has a meta refresh" as an error. That's the check that catches "we renamed the page and forgot half the inbound links."

Backup directories. Our repo accumulates _bak_* folders with old page versions. They're excluded from deploy, so links into them 404 in production even though the files exist locally. The auditor excludes _-prefixed directories from the target set - so a link pointing into one fails the audit, which is exactly what we want.

The _ prefix and .bak trap in the other direction. Cloudflare Workers' assets handling refuses to serve certain paths. Anything under an underscore-prefixed directory or ending in .bak comes back 404 even if the file was uploaded. If you don't model this, you get links that pass the file-tree audit and die at the edge. We model it: the auditor's "deployable file set" is the file tree minus underscore-prefixed dirs, minus .bak files. That set is the ground truth.

Fragment vs. query string

One related fix that fell out of the audit: our contact page takes pre-fill parameters for the inquiry form. Those were query strings (?product=X&request=Y), which meant every parameterized combination was a distinct crawlable URL - hundreds of them showed up in Search Console as duplicates.

The pre-fill logic is client-side JavaScript. Query strings were never needed; fragment identifiers (#product=X) carry the same data to the same JS and are never sent to the server or treated as distinct URLs. One mechanical change, and an entire category of duplicate-URL noise stopped being produced.

The check that turned out to matter more than 404s: orphans

A broken link is loud. An orphan page is silent - no incoming links at all, so crawlers and users simply never find it. Once the link graph is in memory, checking for orphans is free: count incoming edges per page.

Our audit flagged exactly three pages with zero inbound links. That sounds alarming until you look at the list: the 404 page itself, a thank-you page, and a search-engine verification file. Zero true orphans - and more usefully, zero pages with fewer than eight inbound links.

That second number is the one I actually care about: it proves the audit answers "is everything that should be linked actually linked," not just "do the links resolve." That distinction matters because the two questions have opposite failure modes. Broken links show up as errors. Under-linked pages show up as nothing at all - you have to go looking for them with a query nobody thinks to run.

Numbers

  • Pages audited: 1,001 (822 articles across six languages + 179 root pages)
  • Internal link references: 131,832
  • Average internal links per page: ~130
  • Broken at first run: 31 (mostly renames and links into backup dirs)
  • After fixes: 0, held at 0 across every commit since
  • Orphan pages: 3 flagged, 0 true orphans (404 page, thank-you page, search-engine verification file)
  • Pages with fewer than 8 inbound links: 0
  • Audit runtime: ~4 seconds, no network

The deploy pipeline now refuses to ship with a non-zero count. That's the whole trick, honestly: make the audit fast and make it block. Everything else is detail.

What I'd tell past me

Crawl-based link checkers are monitoring; graph-based audits are engineering. You want the second one. And model your host's serving rules - underscore-prefix exclusions, extension whitelists, whatever they are - inside the auditor, because "the file exists" and "the edge will serve it" are not the same sentence on any platform.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.