Search code examples
angularuniversal

Image loaded twice in background-image in css file with angular universal build


I set image to background-image for div in home page in my site in scss file:

    background-image: url('../../../assets/images/map.png');

this work correctly when using ng serve.

But when I build with npm run build:ssr and run node server.js, the image is loaded twice - first loading fails, and second succeeds:

enter image description here amyar24.com

in server.js changed to background-image: url('map.png');

How to avoid loading that image twice?


Solution

  • In CSS you dont have to write background-image instead you can write CSS as follows

    .mycssclass{
        background: url('/assets/myimage.png');
        background-size: contain;
    }
    

    P.S. - it works for me and it dont loads the image twice