Is it feasible to dynamically update the CSS image referenced by a provided URL in
"background-image: \"<some-url>\"
using JavaScript, but only when the source image is modified on the server? The idea is to cache the image and then compare it with the cached version before reloading it upon detecting any changes. To achieve this, one approach involves adding a timestamp parameter to the image URL to force a refresh whenever necessary. This can be done by appending the result of Date.getTime
after the question mark (?). Here's an example (courtesy of this Stack Overflow post):
$(".some-css-class").css("backgound-image", "url(\"" + some_source + "?" + new Date().getTime() + "\"" + ")");
However, I'm interested in implementing this logic only when there are actual updates to the background-image
. Is there a method available to identify such changes automatically?