The Cloudflare Worker code behind favicon.blueat.net favicon.blueat.net
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

JavaScript 100.0%
2 1 0

Clone this repository

https://tangled.org/danielmorrisey.com/favicon.blueat.net https://tangled.org/did:plc:l37td5yhxl2irrzrgvei4qay/favicon.blueat.net
git@tangled.org:danielmorrisey.com/favicon.blueat.net git@tangled.org:did:plc:l37td5yhxl2irrzrgvei4qay/favicon.blueat.net

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

favicon.blueat.net#

A small Cloudflare Worker that fetches a website’s favicon by domain, caches responses at the edge, and returns the image (or a redirect fallback).

Quick start#

npm install
npm run dev

Open http://localhost:8787/example.com while dev is running.

Deploy:

npx wrangler login   # once per machine
npm run deploy

Edit wrangler.toml and set name to the Worker name you want in Cloudflare.

Usage#

Request path is the domain (no protocol):

URL Meaning
/{domain} Resolve favicon for domain

Query parameters

Param Effect
larger=true Prefer larger icons (e.g. Google s2 at 128px, SVG, or big apple-touch sizes from HTML)
default-avatar=<url> If no favicon is found, 302 redirect to this URL
throw-error-on-404=true If no favicon is found, return 404 instead of redirecting

Successful responses include Cache-Control, Access-Control-Allow-Origin: *, and X-Favicon-Source describing where the icon came from.

How it works#

  1. Check the Workers cache for this domain (and larger flag).
  2. If larger, try Google’s favicon service at 128px.
  3. Otherwise fetch the site HTML and parse <link rel="icon"> / apple-touch-icon tags.
  4. Fall back to /favicon.ico, then Google’s 32px favicon.
  5. If nothing works, redirect to a default image or your default-avatar, or 404 when requested.

Files#

  • worker.js — Worker entrypoint
  • wrangler.toml — Wrangler project config

License#

Use and modify as you like for your own deployment.