Using default favicon configuration, auto-lookup without any favicon tag inside html head.
After initial favicon is cached by browser (Firefox 74.0), changing the favicon.ico has no effect when reloading page.
Using the fix suggested in Stackoverflow by adding the link inside html's head with ?v=2
works as expected.
To resolve this issue, shouldn't a hash be appended to favicon, like /favicon.ico?v=<hash>
?
Comment From: wilkinsona
Spring Boot makes the favicon available as a static resource. How you link to it is out of Spring Boot's control. You could choose to use the built-in support for cache busting to help you.
Comment From: cdalexndr
The following configuration doesn't work for favicon.ico
:
spring.resources.chain=true
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**/*.ico,/*.ico,/favicon.ico
spring.resources.chain.cachecontrol.cache-public=true
spring.resources.chain.cachecontrol.max-age=31557600
Firefox debug request info:
Request URL:http://localhost:8081/favicon.ico
Request Method:GET
Request headers:
Host: localhost:8081
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0
Accept: image/webp,*/*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Cookie: <redacted>
Cache-Control: max-age=0
Comment From: wilkinsona
You'll need to link to the favicon from each page that your app serves in a manner that makes use of the resource chain's cache busting. There's a callout about this in the documentation that I linked to above:
Links to resources are rewritten in templates at runtime, thanks to a ResourceUrlEncodingFilter that is auto-configured for Thymeleaf and FreeMarker. You should manually declare this filter when using JSPs. Other template engines are currently not automatically supported but can be with custom template macros/helpers and the use of the ResourceUrlProvider.
Comment From: cdalexndr
Indeed, adding the favicon link in html works:
<link rel="icon" th:href="@{/favicon.ico}" />
The default favicon serving mechanism would benefit from url versioning, but the workaround is an easy fix.