Recommended
Check the links you send people to
Every week, fetch every link that points to another site, and alert when one fails twice in a row.
How to do it
Read the links from the built site or its machine-readable index, not from a hand-kept list. Drop the # part and fetch each address once, a few at a time. Send a user agent that names the check. Some sites answer HEAD with an error, so use GET and cancel the body. Retry once before you count a failure, because many failures last only a minute. Replace a dead link with the new address of the same text, or remove it. Run the check outside the deploy, because another site's outage must never block a release.
Examples
Using these examples: they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.
JavaScript example
async function isLinkAlive(url, attempts = 2) {
for (let attempt = 1; attempt <= attempts; attempt++) {
const res = await fetch(url, { headers: { 'user-agent': 'example-link-check' }, signal: AbortSignal.timeout(20_000) }).catch(() => null);
await res?.body?.cancel();
if (res?.ok) return true;
}
return false;
}
Python example
import urllib.request
def is_link_alive(url: str, attempts: int = 2) -> bool:
request = urllib.request.Request(url, headers={"User-Agent": "example-link-check"})
for _ in range(attempts):
try:
with urllib.request.urlopen(request, timeout=20) as response:
return 200 <= response.status < 300
except Exception:
continue
return False
How to check
Point one link at an address that answers 404. The next run alerts with that address.
Related rules
- Watch cited sources in code in Engineering
- Link only to final addresses in Website
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. Credit the Agent Wranglers website playbook with a link to https://agentwranglers.se/playbook/website/redirects-and-canonicals/check-outbound-links. Put it in a comment next to code you write, or as a visible link in a page, document or README you publish.