An open community 
of Macintosh users,
for Macintosh users.

FineTunedMac Dashboard widget now available! Download Here

Topic Options
#12793 - 11/16/10 10:33 PM What and why is "Webpage Previews?"
artie505 Online


Registered: 08/04/09
It's located at ~/Library/Caches/com.apple.Safari/Webpage Previews, neither clearing either Safari's history or cache nor restarting clears it, it stores both .jpeg and .png images of each web page, and I've seen it grow to more than 50Mb. (I guess it's time to give it its head and see if it purges itself at some point.)

I don't think it's the spawn of anything I've ever run on my deuced Mac(hina)...certainly nothing I'm running now other than, I guess, Safari, in which case, why doesn't Safari clean up after itself?


Edited by artie505 (11/17/10 12:07 AM)
Edit Reason: Cleanup
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top
#12795 - 11/17/10 02:53 AM Re: What and why is "Webpage Previews?" [Re: artie505]
jchuzi Online


Registered: 08/04/09
Loc: New York State
I can't explain it either but I can confirm your observation. That folder is 11 MB in my system. I don't know how big it was originally (your post is the first that I knew of this) but clearing the Safari cache had no effect. I don't want to clear the Safari history because I want to keep it.
_________________________
Jon

OS 10.14.3, iMac Retina 5K 27-inch, late 2014, 3.5 GHz Intel Core i5, 1 TB fusion drive, 16 GB RAM, Epson SureColor P600, Photoshop CC, Lightroom CC, MS Office 365

Top
#12796 - 11/17/10 03:20 AM Re: What and why is "Webpage Previews?" [Re: jchuzi]
artie505 Online


Registered: 08/04/09
Originally Posted By: jchuzi
I can't explain it either but I can confirm your observation. That folder is 11 MB in my system. I don't know how big it was originally (your post is the first that I knew of this) but clearing the Safari cache had no effect. I don't want to clear the Safari history because I want to keep it.

As I said, Jon, nothing I do with Safari has any effect on that file other than making it grow larger; I either clear it manually or let Yasu take care of it (although I have no idea why Yasu clears something that Safari, itself, doesn't clear).

I'm going to let mine run for a while and see how big it gets and whether it clears itself at some point.

What really mystifies me is why it saves its contents as both jpegs and pngs?
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top
#12797 - 11/17/10 03:41 AM Re: What and why is "Webpage Previews?" [Re: artie505]
artie505 Online


Registered: 08/04/09
I just did some searching and found that the issue goes back to at least early 2009...Safari 4 (with Hal involved in a discussion at Ars Technica in which file sizes on the order of 2-3Gb were reported); it apparently has something to do with Safari's "Top Sites" feature.

I also found this "fix".


Edited by artie505 (11/17/10 03:51 AM)
Edit Reason: xpanded first paragraph
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top
#12801 - 11/17/10 04:13 AM Re: What and why is "Webpage Previews?" [Re: artie505]
dkmarsh Offline
Moderator

Registered: 08/04/09

I think the purpose of that folder is to maintain a cache of webpage images used by Safari's Top Sites and visual (i.e. Cover Flow) history features. You can delete the folder's contents by going to the Safari menu, choosing Reset Safari..., and unchecking all but the Remove all webpage preview images checkbox, then clicking the Reset button.

It's just as easy to select the folder in Finder and move it to the Trash; it'll be regenerated on Safari's next launch. Interestingly, if upon relaunch you open Safari's History -> Top Sites page, the recreated folder will re-populate itself with images of a default set of sites, pair by pair, as the pages are loaded into Top Sites and captured as images.

As for the dual sets of images, if you open any of them, you'll find that the jpegs are smaller thumbnail images, and the pngs are full-size screen captures; it appears that the former are used for the display of images in Top Sites or Cover Flow history pages, and the latter are used as full-size temporary placeholders for live content if you click on a Top Sites image.

There appear to be multiple techniques for disabling the caching of such images; locking the Webpage Previews folder is one which I tried, and which seems (so far) to be working.
_________________________

dkmarsh • member, FineTunedMac Co-op Board of Directors

Top
#12804 - 11/17/10 08:39 AM Re: What and why is "Webpage Previews?" [Re: dkmarsh]
dkmarsh Offline
Moderator

Registered: 08/04/09

An AppleScript solution.

Code:
set thePath to ((path to library folder from user domain) as Unicode text) & "Caches:com.apple.Safari:Webpage Previews"
tell application "Finder"
	if (exists folder thePath) then
		delete folder thePath --move "Webpage Previews" to Trash
	else
		display dialog "Folder doesn't exist."
	end if
end tell
_________________________

dkmarsh • member, FineTunedMac Co-op Board of Directors

Top
#12806 - 11/17/10 10:34 AM Re: What and why is "Webpage Previews?" [Re: dkmarsh]
ganbustein Offline


Registered: 08/04/09
To also create an empty locked folder:
Code:
set theLocation to ((path to library folder from user domain) as Unicode text) & "Caches:com.apple.Safari"
set thePath to theLocation & ":Webpage Previews"
tell application "Finder"
	if (exists folder thePath) then
		delete folder thePath --move old "Webpage Previews" to Trash
	else
		display dialog "Folder doesn't exist."
	end if
	tell folder theLocation
		make new folder with properties {name:"Webpage Previews", locked:true}
	end tell
end tell

Top
#12807 - 11/17/10 12:39 PM Re: What and why is "Webpage Previews?" [Re: dkmarsh]
artie505 Online


Registered: 08/04/09
Thanks for the clarification.

Locking the empty folder is working for me, too, so far. (I totally forgot to look at the "Reset" pane, but, under any circumstances, I find it too cumbersome to work with.)

Don't you think it's kind of odd that a cache that can grow to a humongous size is more or less shrouded in secrecy?
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top
#12809 - 11/17/10 03:07 PM Re: What and why is "Webpage Previews?" [Re: artie505]
ryck Online


Registered: 08/04/09
Loc: Okanagan Valley
Originally Posted By: artie505
".... and I've seen it grow to more than 50Mb.

I've been following this thread so, out of curiosity, I checked the size of that folder on my drive. It's 577.6 MB, but I still have nearly 270 GB of space on a 320 GB drive, so I guess I'm a ways away from needing to be concerned.

ryck


Edited by ryck (11/17/10 03:07 PM)
_________________________
ryck

iMac (Retina 5K, 27", 2017), 3.4 GHz Intel Core i5, 8GB RAM, 2400 MHz DDR4
OS High Sierra 10.13.6
Canon MX712 Printer
Epson Perfection V500 Photo Scanner
Time Machine on 320GB OWC Mercury OTG Pro
Super Duper on 500GB OWC Mercury OTG Pro

Top
#12810 - 11/17/10 03:28 PM Re: What and why is "Webpage Previews?" [Re: dkmarsh]
MacManiac Online

Moderator

Registered: 08/04/09
Loc: Paradise....on the central Ore...
An alternative Finder solution would be to get Info on the folder after having dragged the contents to the trash, then simply change the Sharing & Permissions parameters to "Read Only" for yourself as owner and leave the already set parameters for everyone to be "No Access" as it currently is set.....the end result is the same as locking the folder.....

So, navigate into your Home directory /Caches/apple.com.safari/Webpage Previews and drag the contents to the trash and then empty the trash......next, navigate one level up into the com.apple.safari folder and highlight the Webpage Previews folder then either use the Command I keyboard combo or pull down the File Menu to select the Get Info option and then change the owner's (your) permissions from "Read & Write" to "Read Only".....now that folder will no longer accept any further input until you change it back to "Read & Write".
_________________________
Freedom is never free....thank a Service member today.

Top
#12820 - 11/19/10 10:28 PM Re: What and why is "Webpage Previews?" [Re: MacManiac]
artie505 Online


Registered: 08/04/09
I've tried both locking the folder and changing permissions on it, and both approaches have unhappily resulted in many Console entries such as this one:

Code:
11/20/10 2:13:48 AM	[0x0-0x15b15b].com.apple.Safari[1253]	ImageIO: could not open '/Users/artie/Library/Caches/com.apple.Safari/Webpage Previews/.532AF04D3CB00E5E21C6A7A2B5387722.png-48LM'

(At the moment, "1079 of 4000 messages from 11/17/10 6:15:06PM to 11/20/10 2:14:06AM" are variations of that message.)

Both AppleScripts that have been posted both look like they'll leave me in the same position, so I'm wondering whether there's any way to both have my cake and eat it, i.e. prevent the images from being created/cached and not see all those Console messages?

Thanks.
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top
#12826 - 11/20/10 11:25 AM Re: What and why is "Webpage Previews?" [Re: artie505]
Hal Itosis Offline


Registered: 09/03/09
Loc: 10.6.8 (build 10K549)
Originally Posted By: artie505
so I'm wondering whether there's any way to both have my cake and eat it, i.e. prevent the images from being created/cached and not see all those Console messages?

A periodic script to nuke them is probably the easiest:

rm -f ~/Library/Caches/com.apple.Safari/Webpage\ Previews/*

Use launchd to drive it (or an AppleScript scheduled with iCal maybe).

--

Hmm, launchd is a pain sometimes. It won't operate in such a way that allows using the tilde (~) or the asterisk (*) like we can on the command line, and in scripts. So we can't feed it that exact line (which only removes files), but instead we would have to remove the whole folder. [i.e., if we were going for a "launchd-only" solution.] And i'm not sure how Safari will act if the folder is there one minute and gone the next.

So the way we'd need to do it is to put that command in a shell script, and then call that script with launchd.




Edited by Hal Itosis (11/20/10 12:33 PM)

Top
#12827 - 11/20/10 01:58 PM Re: What and why is "Webpage Previews?" [Re: Hal Itosis]
ganbustein Offline


Registered: 08/04/09
You can do it with launchd, if you must. There are two ways:
Code:
<key>ProgramArguments</key>
<array>
    <string>/bin/rm</string>
    <string>-f</string>
    <string>~/Library/Caches/com.apple.Sarari/Webpage Previews/*</string>
</array>
<key>EnableGlobbing</key>
<true/>
or
Code:
<key>ProgramArguments</key>
<array>
    <string>/bin/bash</string>
    <string>-c</string>
    <string>rm -f ~/Library/Caches/com.apple.Safari/Webpage\ Previews/*</string>
</array>

Note that in the first form the space in "Webpage Previews" should not be escaped, since the whole point of specifying ProgramArguments as an array is to describe the end result after shell expansion, so that word splitting and quote removal have already been done. (EnableGlobbing has the side effect of forcing another round of quote removal, so escaping the space will do no harm, but you should not get in the habit of doing unnecessary quoting. In the absence of EnableGlobbing, any quoting characters will be passed along to the process being launched.) In the second form, on the other hand, we're introducing another copy of the shell, which will do all the normal command-line expansion, so normal command-line quoting rules apply.

But perhaps easier would be eschew launchd and use Folder Actions instead:
Code:
on adding folder items to this_folder after receiving added_items
    repeat with afile in added_items
        tell application "System Events"
            delete afile
        end tell
    end repeat
end adding folder items to

Note that you tell System Events to delete the files. If you tell Finder to delete them, it'll just move them to the Trash, cluttering up your Trash. (I hate it when programs do that. It's my Trash, for files I delete.)

Top
#12828 - 11/20/10 11:00 PM Re: What and why is "Webpage Previews?" [Re: ganbustein]
artie505 Online


Registered: 08/04/09
Thanks for the script, but I've followed every instruction I can find (*) and can't get the Folder Action to run...

Code:
11/21/10 2:41:32 AM	com.apple.launchd.peruser.501[125]	(com.apple.FolderActions.folders) Throttling respawn: Will start in 10 seconds

Any ideas?

Addendum: I tried saving the script both with and without checking the "Run Only" box...no difference.

(*) Being more specific...
  1. I compiled your script
  2. I saved it, both ways, as mentioned, to ~/Library/Scripts/Folder Action Scripts
  3. I enabled the Folder Action by control-clicking on ~/Library/Caches/com.apple.Safari/Webpage Previews and following the instructions.


Edited by artie505 (11/20/10 11:26 PM)
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top
#12832 - 11/21/10 10:42 AM Re: What and why is "Webpage Previews?" [Re: ganbustein]
Hal Itosis Offline


Registered: 09/03/09
Loc: 10.6.8 (build 10K549)
Originally Posted By: ganbustein
You can do it with launchd, if you must. There are two ways:
Code:
<key>EnableGlobbing</key>
<true/>

Ah-ha... sneaky. [i' didn't yet delve into that globbing discussion over at macosxhints. Now that i've seen *this* example, i shalll remember it.]


Originally Posted By: ganbustein
or
Code:
    <string>/bin/bash</string>
    <string>-c</string> 

Also slick (and makes sense). Thanks.


Originally Posted By: ganbustein
Note that in the first form the space in "Webpage Previews" should not be escaped, since the whole point of specifying ProgramArguments as an array is to describe the end result after shell expansion, so that word splitting and quote removal have already been done. (EnableGlobbing has the side effect of forcing another round of quote removal, so escaping the space will do no harm, but you should not get in the habit of doing unnecessary quoting. In the absence of EnableGlobbing, any quoting characters will be passed along to the process being launched.) In the second form, on the other hand, we're introducing another copy of the shell, which will do all the normal command-line expansion, so normal command-line quoting rules apply.

Argh... my head hurts. laugh
[but i got most of it.]

Top
#12834 - 11/21/10 12:26 PM Re: What and why is "Webpage Previews?" [Re: artie505]
ganbustein Offline


Registered: 08/04/09
It looks like the folder action is encountering an error. It may be a race condition; it's trying to delete a file that is still being created, or maybe already in use after being created.

The script is certainly being too aggressive. The problem we're trying to address is not so much that the Web Previews folder has anything in it, as that what's being put there never gets cleaned out. Let's solve the race condition by only deleting old files:
Code:
on adding folder items to thisFolder after receiving someFiles
	set folderPath to quoted form of POSIX path of thisFolder
	do shell script "cd " & folderPath & "; find . -atime +24h -delete"
end adding folder items to

In this version, every time anything is added to the folder we'll delete anything that hasn't been accessed in the last 24 hours. If Safari hasn't used one of these files recently, it probably won't need it soon. Conversely, if it has used something recently and we delete it, it'll probably re-create it soon, which only wastes cycles.

For testing purposes, I duplicated the Web Previews folder and set the folder action on that. I also had to replace -atime with -mtime (modify time rather than access time) because the act of copying the folder accessed all the items. You might also need to use -mtime instead of -atime, but don't do that until you've run it for a couple of days and find that it isn't deleting enough. Even if Safari isn't modifying a file, if it's even using it it's doing some good.

Top
#12835 - 11/21/10 04:04 PM Re: What and why is "Webpage Previews?" [Re: ganbustein]
dkmarsh Offline
Moderator

Registered: 08/04/09

Quote:
Note that you tell System Events to delete the files. If you tell Finder to delete them, it'll just move them to the Trash, cluttering up your Trash. (I hate it when programs do that. It's my Trash, for files I delete.)

You can tell Finder to delete the files, then send it the empty command, but of course this risks throwing out the baby with the bathwater for folks who use the Trash to hang on to items they're not quite ready to nuke.

Another way around the Console error issue is simply to quit Safari with a script which deletes the folder or its contents:

Code:
set thePath to ((path to library folder from user domain) as Unicode text) & "Caches:com.apple.Safari:Webpage Previews"
tell application "Finder"
	delete folder thePath --move "Webpage Previews" to Trash
	empty --warning: empties the Trash! Delete this line if you use the Trash to store stuff!
end tell
tell application "Safari" to quit

Or use System Events for the deletion. The point is that quitting (or launching) an app with an AppleScript script is an easy way to perform tasks which don't need to happen on a schedule as long as they happen more or less regularly. (Of course, this doesn't work if you're always up and never quit Safari, but I've never had so much RAM that Safari couldn't benefit from an occasional relaunch, even now that its memory leaks seem to be a thing of the past.)
_________________________

dkmarsh • member, FineTunedMac Co-op Board of Directors

Top
#12858 - 11/22/10 10:38 PM Re: What and why is "Webpage Previews?" [Re: ganbustein]
artie505 Online


Registered: 08/04/09
Thanks for the update, but I've run into a new issue (which either didn't show up immediately or went unnoticed confused ), wherein every time a Folder Action is invoked it causes Safari's tool and bookmarks bars to "flash," which I find unacceptable.

In addition, after giving the matter some thought I've realized that none of the solutions offered up so far deals with my situation... I never use either Top Sites or Cover Flow, and rather than deleting Webpage Previews that have already been cached I prefer that they never be created in the first place.

So... I went back to Google and found Disable Webpage Preview Images in Safari 4 Final, which is working like a dream in Safari 5.0.3.

To all who've kicked in, thanks, and to all who are waiting with baited breath, go for it! cool grin


Edited by artie505 (11/22/10 10:51 PM)
_________________________
The new Great Equalizer is the SEND button.

In Memory Of Harv: Those who can make you believe absurdities can make you commit atrocities. ~Voltaire

Top

Moderator:  alternaut, dianne, MacManiac