1

I have a React App, that basically updates a bunch a class on a container, so the background image can be changed a random intervals.

I'd like to preload these images, so once their respective class is applied, they are avaible and not subject to latency of a network request and the user's browser.

Are there suggested best practices for preloading assets such as background images?

Harry Blue
  • 4,202
  • 10
  • 39
  • 78
  • 1
    if you simply cache them, then you're fine - no latencies. Other than that those two answers should help you https://stackoverflow.com/questions/3646036/javascript-preloading-images + https://stackoverflow.com/questions/35657387/how-do-i-use-a-new-image-in-react – Lyubomir Jan 03 '18 at 10:15
  • 1
    yep just use the simple standard JS way of preloading via a new in memory Image object as those answers suggest, no need to overcomplicate with a React specific solution! Once loaded in memory, the browser cache will fulfil any subsequent requests even if via `` (as long as image is served with no cache busting headers of course) – alechill Jan 03 '18 at 11:02

0 Answers0