Custom favicon in Yii2

as rkm mentioned it's because of browser cache. Easy fix is to add version like ../favicon.ico?v=1 and browser will load new version.


You can do this as simple as adding an extra line to your AppAsset.php file:

public $css = [
        [
            'href' => 'path-to-your-icon/icon-32x32.png',
            'rel' => 'icon',
            'sizes' => '32x32',
        ],
        [
            'href' => 'path-to-your-icon/icon-192x192.png',
            'rel' => 'icon',
            'sizes' => '192x192',
        ],
        [
            'href' => 'path-to-your-icon/icon-180x180.png',
            'rel' => 'apple-touch-icon-precomposed',
        ],
        'css/site.css',        
    ];

Hope it will helps.


Another way to set the favicon as described in the documentaion is by adding something like this to the main.php file located under views/layouts. $this->registerLinkTag(['rel' => 'icon', 'type' => 'image/png', 'href' => '/favicon.png']);

Tags:

Php

Yii2