Home >Web Front-end >CSS Tutorial >Favicons: How to Make Sure Browsers Only Download the SVG Version

Favicons: How to Make Sure Browsers Only Download the SVG Version

Lisa Kudrow
Lisa KudrowOriginal
2025-03-18 11:26:14726browse

Favicons: How to Make Sure Browsers Only Download the SVG Version

Recently, Šime Vidas highlighted a Twitter thread discussing favicon HTML. My initial favicon code contained a typo:

<link href="/favicon.ico" rel="icon" size="any"><link href="/favicon.svg" rel="icon" type="image/svg xml">

The correct code uses sizes instead of size:

<link href="/favicon.ico" rel="icon" sizes="any"><link href="/favicon.svg" rel="icon" type="image/svg xml">

This correction prevents Chrome from downloading both the ICO and SVG favicons, ensuring only the SVG (the preferred format) is used. My ICO file is 5.8kb, representing a non-negligible saving per page load.

Šime mentioned this in Web Platform News #42, noting that while SVG favicons are supported by all modern browsers except Safari, declaring both ICO and SVG requires the sizes="any" attribute on the ICO <link> tag to prevent Chrome from prioritizing the ICO. (See Chrome bug 1162276 for details). He cited CSS-Tricks as an example of optimal markup, though this was only true after the error was identified. The original typo likely stemmed from a previous article (now corrected), but Andrey's article remains a valuable resource for practical favicon implementation.

The above is the detailed content of Favicons: How to Make Sure Browsers Only Download the SVG Version. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn