Leo Jiang
Leo Jiang

Reputation: 26223

Javascript: Clear cache on redirect

I can use location.reload(true) to refresh the page and refetch the page. I want to redirect the user to a new URL and clear the cache.

More specifically, I have a "Clear all cookies" button that redirects the user to the homepage after being clicked. I want the homepage to be refreshed.

Upvotes: 4

Views: 15672

Answers (2)

honyovk
honyovk

Reputation: 2747

Do something like:

var loc = window.location.href; // or a new URL
window.location.href = loc + '?n=' + new Date().getTime(); // random number

EDIT: The only option for reloading static resources (see comment below) would be to append the random number to their URLs server-side by listening for the 'n' query string.

Upvotes: 12

Elliot Bonneville
Elliot Bonneville

Reputation: 53361

Sorry, but you can't clear the cache with Javascript.

Upvotes: -4

Related Questions