Favicons Proxy is a Cloudflare Worker that serves as a middleman for fetching website favicons. It attempts to retrieve favicons from multiple sources in a specified order, ensuring that you get the best available icon for any given domain.
- Fetches favicons from multiple sources:
- Google Favicons
- DuckDuckGo Icons
- Icon Horse
- Handles failed requests gracefully by trying the next source
- Validates domain format before making requests
- Caches successful responses for improved performance
- Simple to use with a clean URL structure
To use the Favicons Proxy, simply make a GET request to the worker URL with the desired domain:
https://favicons.seadfeng.workers.dev/example.com.ico
Replace example.com
with the domain you want to fetch the favicon for.
- The worker receives a request for a domain's favicon.
- It validates the domain format to ensure it's potentially valid.
- If the domain is valid, it attempts to fetch the favicon from the following sources in order:
https://www.google.com/s2/favicons?domain=${domain}&sz=50
https://icons.duckduckgo.com/ip3/${domain}.ico
https://icon.horse/icon/${domain}
- If a favicon is successfully retrieved from any source, it is returned to the user.
- If all sources fail, a 404 error is returned.
To deploy this worker:
- Log in to your Cloudflare dashboard.
- Navigate to the Workers section.
- Create a new Worker.
- Copy the provided Worker script into the editor.
- Save and deploy the Worker.
- (Optional) Set up a custom subdomain for your Worker, e.g.,
favicons.yourdomain.workers.dev
.
The Worker doesn't require any additional configuration. However, you can modify the sources
array in the script if you want to add, remove, or reorder the favicon sources.
- The proxy doesn't verify if the returned image is actually a favicon; it trusts the source.
- It always returns the Content-Type as
image/x-icon
, which may not be accurate for all responses. - There's no built-in rate limiting, so consider implementing this if you expect high traffic.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
Created by Sead Feng