B
B
bitwheeze2021-11-03 11:15:52
css
bitwheeze, 2021-11-03 11:15:52

How to load images before using in css?

For the sake of self-development, I wrote a card game for the browser. Powered by next.js/react.js framework. The cards are rendered as background-image to the div.

<div class="card_card__2PMY2 " style="background-image: url('TS.png');"></div>


The images are in the project in the public folder. On trial, I made a simple animation. The card just shifts slightly when flipped.

Everything works as long as the connection to the server is good. With a bad connection, the cards are shifted jerkily and it seems that the whole game slows down while the picture is loading. I activated the cache on the server (nginx), plus the pictures are cached in the browser. But when you start the game and while there are no images in the browser cache, the display slows down. Until all 52 cards are loaded.

The question is, how would I load all the map images in the background into the browser cache when I open the site. How do senior comrades do it? What are the ways?

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-11-03
@idruweb

1) upload a photo with a script
2) make a sprite

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question