Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

View Safari cache files while offline Web Browsers
I was using my PowerBook on the bus the other morning and was desperate to view a page I had looked at a few days prior in Safari. Since I had rebooted the night before, it was not on the previous page arrow pulldown menu. Safari's great History apparently only remembers the URL and not the link to cache files, which is a real shame, since this would be great for occasional off-line viewing without having to remember to grab the page before you go off-line.

So, I went delving into Safari cache files (~/Library -> Cache -> Safari) to find the page I wanted. Fortunately, using grep from the command line (or the Finder's search -- but remember that the Finder's search is not case sensitive), it's easy to find a cache file with some content that corresponds to the page you want to display. But unfortunately, the file is of type .cache, and not just the original .html file. The HTML is contained in the cache file, however.

Safari won't open these files from it's File -> Open menu, but to my surprise, it did display them with a drag and drop from the Finder! There is header and footer garbage displayed from the remaining contents of the .cache file, but for the few cases I tried, Safari found the HTML and rendered the page well enough for me to get what I needed off of it.

I know there are a lot of cache emptiers out there, but are there any Cache viewing apps or a utility to strip the HTML out of the cache files to make the viewing even nicer?
  • Currently 3.17 / 5
  You rated: 5 / 5 (6 votes cast)

View Safari cache files while offline | 6 comments | Create New Account
Click here to return to the 'View Safari cache files while offline' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View Safari cache files while offline
Authored by: dknecht on Oct 28, '03 12:02:54PM

There is an example application in the Developer --> Example --> WebKit called DiskCacheInspector. You will need to have Xcode or Project Builder installed to compile the application. Once compiled it will startup and load all the cache files into a list that will allow you to view the content as raw html. I then just copy the html to a file and view it in Safari or paste it into an active SubEthaEdit (Hydra) document and use the built in html client. I am sure a saavy programmer can easily improve on this code and build and all in one app.

I have compiled a copy for those of you that don't have Xcode or Devloper tools. I didn't write this program and it is copyrighted to Apple Computer

[ Reply to This | # ]
View Safari cache files while offline
Authored by: jlongs2 on Dec 24, '04 04:07:53AM

In consideration of your agreement to abide by the following terms, and subject to these
terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in
this original Apple software (the "Apple Software"), to use, reproduce, modify and
redistribute the Apple Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the Apple Software in its entirety and without
modifications, you must retain this notice and the following text and disclaimers in all
such redistributions of the Apple Software. Neither the name, trademarks, service marks
or logos of Apple Computer, Inc. may be used to endorse or promote products derived from
the Apple Software without specific prior written permission from Apple. Except as expressly
stated in this notice, no other rights or licenses, express or implied, are granted by Apple
herein, including but not limited to any patent rights that may be infringed by your
derivative works or by other works in which the Apple Software may be incorporated.

So this means that allowed to modify the source and redistribute the modifications, in source or binary, as long as... I don't give credit to Apple? Apple has a strange license...

[ Reply to This | # ]
View Safari cache files while offline
Authored by: oliverlangan on Sep 03, '09 03:01:19PM

Since this was posted, it seems that the cache file format has changed. It is now a SQLite database. The file can be found in the current user's folder:
You can browse the file with the sqlite3 command line tool, but it will be much easier to extract data if you use a GUI tool such as MesaSQLite.

[ Reply to This | # ]
View Safari cache files while offline
Authored by: tehthehteh on Nov 28, '11 04:31:34PM
Thanks for the tip! MesaSQLite looks great.

I put together this quick hacked shell script below, which gives you an overview of all images in the cache. It extracts the images from the cache, puts together a temporary HTML file on the desktop, opens the page in Safari and deletes it once loaded.
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"" > ~/Desktop/cache.html
echo "    \"\">" >> ~/Desktop/cache.html
echo "<html lang=\"en\">" >> ~/Desktop/cache.html
echo "  <head>" >> ~/Desktop/cache.html
echo "    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">" >> ~/Desktop/cache.html
echo "    <title>Cached Images</title>" >> ~/Desktop/cache.html
echo "  </head>" >> ~/Desktop/cache.html
echo "  <body>" >> ~/Desktop/cache.html
sqlite3 ~/Library/Caches/ "SELECT request_key, time_stamp FROM cfurl_cache_response WHERE request_key LIKE '%.jpg' OR request_key LIKE '%.jpeg' OR request_key LIKE '%.gif' OR request_key LIKE '%.png' ORDER BY time_stamp DESC;" | perl -ne 'chomp; ($url, $time) = split(/\|/); print "<a href=\"$url\"><img src=\"$url\" alt=\"Downloaded at $time\"></a> <a href=\"$url\">$url</a> $time<br>\n";' >> ~/Desktop/cache.html
echo "  </body>" >> ~/Desktop/cache.html
echo "</html>" >> ~/Desktop/cache.html
open -a Safari ~/Desktop/cache.html
sleep 1
rm ~/Desktop/cache.html
Open up Terminal, type "nano cache", paste in this script, save using 'Ctrl-X' and then 'Y'. Run "chmod +x cache" to make it executable. Now, anytime you want to bring up all cached images, you can open up Terminal, type 'cache' and woo! Images! It also keeps the URLs, in case you want to search for a file name. A word of warning though: there might be a lot of images in there.

[ Reply to This | # ]
A cache viewer for Safari
Authored by: jokke on Feb 04, '05 04:19:45PM
Take a look at my rude proof-of-concept Memento [the name will be changed by next release, there's another app with the same name] available at my site. Let me know what you think and any suggestions you might have. There is also a versiontracker page here.

--- | Pulling the trigger at port 80

[ Reply to This | # ]

View Safari cache files while offline
Authored by: x4vl on May 03, '10 01:52:36PM

I use SafariCacheExplorer:

[ Reply to This | # ]