Skip to content

Instantly share code, notes, and snippets.

@Long18
Created April 17, 2024 03:44
Show Gist options
  • Save Long18/59e772bee5f9c9fec161136512c925da to your computer and use it in GitHub Desktop.
Save Long18/59e772bee5f9c9fec161136512c925da to your computer and use it in GitHub Desktop.

Clear Browser Cache Script

This script allows you to clear the browser cache using JavaScript.

javascript:(function(){
  'caches' in window && caches.keys().then(cacheNames => cacheNames.forEach(cacheName => caches.delete(cacheName)));
  localStorage.clear();
  sessionStorage.clear();
  indexedDB.databases().then(databases => databases.forEach(db => indexedDB.deleteDatabase(db.name))).catch(error => console.error('Failed to clear IndexedDB:', error));
  location.reload(true);
})();

Usage

  1. Open your browser.
  2. Navigate to the webpage where you want to clear the cache.
  3. Open the browser's developer tools (usually by pressing F12).
  4. Go to the Console tab.
  5. Paste the script into the console and press Enter.
  6. This script will clear various types of caches, including caches stored in the caches API, localStorage, sessionStorage, and IndexedDB.

Note: This script may not work in all browsers and may have limitations depending on the browser's security settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment