The Problem with Safari’s Cache
When you browse the internet using Apple’s Safari browser on macOS, the application aggressively caches images, CSS files, and JavaScript payloads to ensure that revisiting a webpage is lightning-fast. In addition to basic caching, modern websites utilize LocalStorage and IndexedDB (collectively known as Website Data) to store complex application states entirely offline.
While this dramatically improves performance, a corrupted cache can completely break a specific website. You might try to load your banking portal, only to see a blank white screen, or a web application might get stuck in an infinite redirect loop. While you can use the graphical Safari Preferences menu to click “Clear History,” this action is heavy-handed—it deletes your entire browsing history and signs you out of every single website simultaneously.
If you are a web developer testing a new site deployment, or if you simply want to clear the raw cache files without destroying your active login cookies, you must bypass the GUI and purge the cache directly via the Terminal.
Locating the Cache Directories
Safari’s cache architecture is split into two distinct locations within your user Library folder.
The standard browser caches (images and HTML) are located at: ~/Library/Caches/com.apple.Safari/
The modern Website Data (LocalStorage, IndexedDB, and Service Workers) is sandboxed at: ~/Library/Safari/Databases/ and ~/Library/Safari/LocalStorage/
Purging the Cache via Terminal
Because these directories are owned by your specific user account, you do not need elevated (sudo) privileges. However, you must ensure the Safari application is completely closed; otherwise, the active background processes will immediately recreate the cache files you are trying to delete.
- Quit the Safari application entirely (Command + Q).
- Open the Terminal application.
- Execute the following commands sequentially to forcefully remove the active caches:
# Clear the primary image/HTML cache
rm -rf ~/Library/Caches/com.apple.Safari/*
# Clear the modern Website Data (LocalStorage)
rm -rf ~/Library/Safari/LocalStorage/*
# Clear the IndexedDB Databases
rm -rf ~/Library/Safari/Databases/*
The Hidden WebKit Cache
Safari is built on the WebKit rendering engine. WebKit maintains its own separate, low-level cache layer that often persists even after you clear the primary Safari directories. If a specific CSS file is stubbornly refusing to update after you deploy a change to your web server, you must purge the WebKit cache.
Execute the following command:
rm -rf ~/Library/Caches/com.apple.WebKit.WebContent/*
Verifying the Reset
Once the Terminal commands have executed silently, you can reopen Safari. The browser will take a few extra milliseconds to load your first webpage because it is being forced to fetch every single asset fresh from the remote server, completely bypassing the local hard drive.
By using the Terminal, you have successfully resolved the corrupted cache issue while perfectly preserving your browsing history and active login sessions across the internet.