This repository contains Cloudflare Worker that proxies favicons from websites.
Cloudflare Workers are like serverless cloud functions, but they also can cache stuff in Cloudflare CDN to make things faster. If you are not familiar with Cloudflare Workers, visit Cloudflare Workers documentation. Or you can just press the button instead:
Currently, the worker exposes only one endpoint that returns favicon of requested domain:
<img src="https://your-domain.workers.dev/favicon?domain=google.com" />
Returns the largest favicon associated with passed domain.
What it does under the hood:
- It sends request to
https://{domain}/
to receive HTML of the index page. It may follow redirects if needed. - Then, it looks for
head > link[rel~=icon]
elements to find all favicon links. - It downloads all icons sequentially from largest to smallest until successful download. It prioritizes favicons by
sizes
andtype
attributes. - As fallback, if some previous step failed, request will be sent to
https://{domain}/favicon.ico
.
Clone the repository. Then, install dependencies:
npm ci
Start webpack:
webpack watch
Open another terminal and then run the worker in development mode:
wrangler dev