How to prevent favicon.ico requests
Codemia Knowledge Hub ·
Browsers request /favicon.ico automatically, even when a site has no favicon, which adds an HTTP request on page loads. To stop or reduce these requests, declare the icon explicitly in the HTML head, embed it as a data URL, have the server answer with no content, or cache it aggressively.
Specify the favicon in the HTML head
Defining the favicon path in the <head> tells the browser exactly where the icon is, so it does not try to fetch it from the domain root:
This removes the guesswork request and gives you control over caching for that file.
Embed the favicon as a data URL
A Base64 data URL puts the icon inside the HTML, so there is no separate HTTP request at all:
This suits very small icons, since it slightly increases the HTML size.
Return 204 No Content from the server
If the site has no favicon, configure the server to answer favicon.ico requests without content:
With NGINX:
This tells the browser there is no favicon, stops repeated requests, and serves no data, saving bandwidth.
Cache the favicon for a long time
A long cache lifetime means the browser fetches the icon once and then serves it from cache:
Server load drops over time because repeat visits do not request the file again.
Block favicon requests outright
Generally not recommended, but you can refuse the requests entirely:
This keeps the server from handling these requests, which can help in specific cases where favicons are abused or cause issues.
Which method to choose
| Strategy | Description | Pros | Cons |
| Specify in HTML | Define the path in the HTML document. | Directs the browser efficiently. | Requires modification of HTML. |
| Use a Data URL | Embed favicon using Base64 data. | Eliminates HTTP requests. | Increases HTML size slightly. |
| Send a 204 Status | Configure server to return no content. | Stops unnecessary requests. | Requires server configuration. |
| Leverage Caching | Set caching headers for the favicon. | Reduces request frequency significantly. | Setup complexity on server side. |
| Blocking Requests | Outright block requests to favicon.ico. | Full control over handling favicon. | May not be suitable for all sites. |
Whichever you pick, consider how the change affects users with different configurations or technologies, and test both server-side and client-side performance to confirm the effect.
Related reading
- How to prevent tensorflow from allocating the totality of a GPU memory?
- How to prevent the loss of messages sent by publisher (due to delay in pub sub connection), without using sleep method,in extended PUB-SUB topology?
- How to profile networks in TensorFlow v2
- How to profile TensorFlow networks?
- How to properly manage memory and batch size with TensorFlow
- How to properly reduce the size of a tensorflow savedmodel?
- How to properly reuse connection to Mongodb across NodeJs application and modules
- How to Prove one Random Number Generator is Better Than Another?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.