Web Development
Favicon.ico
Server Requests
Website Optimization
Preventing Requests

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:

html
<link rel="icon" type="image/png" href="/path/to/favicon.png">

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:

html
<link rel="icon" type="image/x-icon" href="data:image/x-icon;base64,AAABAAEAEBA...">

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:

apache
# Apache server configuration
Redirect 204 /favicon.ico

With NGINX:

nginx
location = /favicon.ico {
    return 204;
}

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:

apache
<FilesMatch "favicon.ico">
    Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

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:

apache
Redirect 403 /favicon.ico
nginx
location = /favicon.ico {
    deny all;
}

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

StrategyDescriptionProsCons
Specify in HTMLDefine the path in the HTML document.Directs the browser efficiently.Requires modification of HTML.
Use a Data URLEmbed favicon using Base64 data.Eliminates HTTP requests.Increases HTML size slightly.
Send a 204 StatusConfigure server to return no content.Stops unnecessary requests.Requires server configuration.
Leverage CachingSet caching headers for the favicon.Reduces request frequency significantly.Setup complexity on server side.
Blocking RequestsOutright 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.


Course
Intermediate
27 lessons
15 hours
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 course
Data 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.

Practice algorithms