Search code examples
htmlbrowsersymfony4faviconw3c

Prevent browser from trying to load favicon from root directory


I have a symfony route

    /**
     * @Route("/{connection_name}", defaults={"connection_name" ="error_mail_prod"})
     */
    public function index(Request $request)

And I have specified a favicon

<link rel="icon" type="image/x-icon" href="{{ asset('images/favicon.ico') }}" />

But it looks like the browser is still trying to load a favicon.ico from the root directory. It is requesting the route above ( https://mywebsite/favicon.ico ) with favicon.ico as an option and causing an error.
My favicon is showing up properly. Should I redefined my route ? Or is there any way to prevent the browser from trying to request a favicon at root directory even though I already specified one ?


Solution

  • What you observe is an old convention: browsers are often trying to load /favicon.ico no matter what.

    Solutions:

    • Ignore this issue. This is a perfectly reasonable solution, many sites are doing just this.
    • Make /favicon.ico available (add the file, define the route...) to prevent avoidable 404 errors in your logs.