Safari Empty Caches: Service Workers and Cache Storage
This article provides a quick overview of what happens when you select "Empty Caches" from the Develop menu in the Safari web browser. Specifically, it explains how this action impacts active Service Worker registrations and the Cache Storage API, why Safari treats these elements differently from standard browser caches, and the correct methods to clear them during web development.
What "Empty Caches" Actually Does
When you select Empty Caches (or press
Option + Command + E) from Safari's Develop menu, the
browser purges its traditional HTTP network caches. This includes both
the memory cache and the disk cache used to store standard web assets
like stylesheets, scripts, and images fetched via normal network
requests.
Impact on Service Worker Registrations
Selecting Empty Caches does not unregister or remove Service Workers.
Safari categorizes Service Worker registrations as persistent website
data and application state rather than temporary network cache. After
you empty the caches, any registered Service Worker will remain
installed, active, and in control of the page. It will continue to
intercept network requests (fetch events) just as it did
before you triggered the command.
Impact on Cache Storage
Selecting Empty Caches does not delete data stored
in the CacheStorage API (window.caches).
Although it has the word "cache" in its name,
CacheStorage is a programmable storage mechanism managed
entirely by JavaScript and your Service Worker. Safari groups
CacheStorage alongside other origin-based storage APIs like
IndexedDB and localStorage. Because developers
use CacheStorage to enable offline functionality and store
critical application states, Safari protects this data from being wiped
by a standard HTTP cache purge.
As a result, if your Service Worker is programmed with a
"Cache-First" strategy, reloading the page after clicking Empty Caches
will still serve the old files directly from CacheStorage,
making it appear as though the cache was never cleared.
How to Clear Service Workers and Cache Storage in Safari
To completely remove Service Worker registrations and wipe
CacheStorage in Safari, you must clear the site's
persistent storage using one of the following methods:
Method 1: Using the Web Inspector (Fastest for Developers)
- Open the Safari Web Inspector
(
Option + Command + I). - Navigate to the Storage tab.
- Locate Cache Storage in the left sidebar, right-click the specific cache, and select Delete to clear the stored assets.
- To stop the Service Worker, go to the Sources or
Develop menu, inspect the Service Worker context, and
unregister it, or run
navigator.serviceWorker.getRegistrations().then(r => r.forEach(reg => reg.unregister()))directly in the Console.
Method 2: Clearing Website Data (Complete Reset)
- Open Safari Settings (or Preferences).
- Go to the Privacy tab.
- Click Manage Website Data....
- Search for the domain you are working on, select it, and click Remove.
This second method completely resets the origin, deleting the HTTP
cache, CacheStorage, IndexedDB,
localStorage, cookies, and all Service Worker registrations
simultaneously.