Home > front end >  HTML button to force reload (not using cache) of a static HTML page
HTML button to force reload (not using cache) of a static HTML page

Time:11-12

I've tried several methods, especially all listed here:

...but they all seem to only trigger a reload using local cache.

Is there any way to trigger a forced reload, bypassing any cache (especially for images) via an HTML button?

Alternatively, is there a line of HTML code that would force the page to not use cache at all?

The page is a simple static html page that changes a few times a day.

CodePudding user response:

There is no HTML-only way to do it.

You could try using window.location.reload(true) which will try to reload the current page and ignore cache files on some browsers. But this is not part of the specification and won't work on most browser (https://developer.mozilla.org/en-US/docs/Web/API/Location/reload)


The real way to make it is to version your filenames ! There are many tools to do it quite easily. When the page will refresh, as the name will have changed, your browser is going to load the new file and you won't have cache problem anymore

CodePudding user response:

I'm pretty sure it's not possible to force reload ( clear cache) in HTML itself.

One solution is to make a button and give that a JS function, in which both the cache is cleared and the page reloaded.

function reloadClear() {
  window.localStorage.clear();
  window.location.reload(true);
  return false;
}

CodePudding user response:

just remove localstorage saved files use window.localstorage.remove('name of the item you saved') or if you didnt what all of them just use window.localstorage.clear() then reload it with window.location.reload(true)

  • Related