Old images loading Cache issue

From UnionCloud Support
Revision as of 10:07, 7 March 2019 by Dannyjkendall12 (talk | contribs) (Created page with "Add the below to Global JS. This will force all image files to reload. '''It works by adding a parameter in this case the current time to the end of the path. This causes th...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Add the below to Global JS. This will force all image files to reload.

It works by adding a parameter in this case the current time to the end of the path. This causes the browser to treat it as new

There maybe a small delay.

function cacheBuster(url) {
    return url.replace(/\?cacheBuster=\d*/, "") + "?cacheBuster=" + new Date().getTime().toString();
}

$("img").each(function() {
    this.src = cacheBuster(this.src);
});

$("*").each(function() {
    var bg_img = $(this).css("background-image");
    if (bg_img !== "none") {
        var url = /url\((.*)\)/i.exec(bg_img);
        if (url) {
            $(this).css("background-image", "url(" + cacheBuster(url[1]) + ")");
        }
    }
}); 

Source: https://stackoverflow.com/users/215969/ilia-choly