[Fixed]-Background image not changing from javascript

2👍

UPDATE 2 – check this question for more info and better ways to acheive that: Refresh image with a new one at the same url

UPDATE:
What helped was saving the images with a new name and send the updated url to the front, as i assumed it have to do with cache, but im not sure why adding ?c=rand didn’t helped.

I assume it will have to do with the cache of the browser.

Try to add timestamp or other rand number to the image url, so you will force to load the new image every time.

x.style.backgroundImage = "url('/static/detect/test.jpg?c=|some random number|')";

you can read more: how to clear or replace a cached image

-1👍

Try this to clear the cache:

x.style.backgroundImage = `url('/static/detect/test.jpg?${Date.now()}')`

Leave a comment