I tried to replace favicon.ico in /web-app/images/ folder but it doesn't work : my site still has the usual Grails favicon. What do I need to do more?
To add a favicon to your website, either save your favicon image to the root directory of your webserver, or create a folder in the root directory called images, and save your favicon image in this folder. A common name for a favicon image is "favicon. ico".
You can't set a favicon from CSS - if you want to do this explicitly you have to do it in the markup as you described. Most browsers will, however, look for a favicon. ico file on the root of the web site - so if you access http://example.com most browsers will look for http://example.com/favicon.ico automatically.
To change favicons dynamically, we will create two javascript functions, to change favicons GeeksforGeeks and Technical Scripter respectively. We will assign a constant variable and get them by the favicon Id with the getElementById() function. After that, we will create 2 functions and assign two buttons for that.
With the grails assets plugin you must use:
<head>
    ...
    <asset:link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
</head>
try to change views\layout\main.gsp
<html>  
    <head>  
        <title><g:layoutTitle default="Grails" /></title>  
        <link rel="stylesheet" href="${createLinkTo(dir:'css',file:'main.css')}" />  
        <link rel="shortcut icon" href="${createLinkTo(dir:'images',file:'favicon.ico')}" type="image/x-icon" />  
        <g:layoutHead />  
        <g:javascript library="application" />                  
    </head>  
    <body>  
        <div id="spinner" class="spinner" style="display:none;">  
            <img src="${createLinkTo(dir:'images',file:'spinner.gif')}" alt="Spinner" />  
        </div>      
        <div class="logo"><img src="${createLinkTo(dir:'images',file:'grails_logo.jpg')}" alt="Grails" /></div>     
        <g:layoutBody />        
    </body>     
</html>
and comment
<link rel="shortcut icon" href="${createLinkTo(dir:'images',file:'favicon.ico')}" type="image/x-icon" /> 
or clean your browser's cache. ;-)
Put favicon.ico file to PROJECT/grails-app/assets/ folder,
add to UrlMappints
class UrlMappings {
    static mappings = {
      ......
      "/favicon.ico"  (uri: "/assets/favicon.ico")
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With