Safari 16 history caching

Does anyone know of a way to prevent Safari 16 (16.2) from caching history? The only option I can find is to set it to "one day". Of course, I can manually do a 3-click process to clear it after each query. But while this restriction might be acceptable for someone simply browsing the web, it's totally unacceptable for developing web code locally, using "Brackets" on a MAMP PRO local installation.


If Neil Armstrong was a programmer, he'd surely note: "Thats one small step for a man, one giant leap [backwards] for mankind."


MacBook Pro 16″, macOS 13.1

Posted on Apr 20, 2023 7:09 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 26, 2023 10:03 AM

I just tested the following AppleScript that I wrote in 2018 on macOS 13.3.1 and it still works to clear all history and the browser cache on Safari 16.4. You could save it first as AppleScript text (source) and then using option+Save As… as an Application that goes on your Dock. Then it is a one-button click solution to clear up Safari.


Open in the Script Editor, click compile, and run.


-- nohistory.applescript
-- Purges all Safari history, the browser cache, and quits the application if it is running.
-- Update: 2023-04-26, macOS 13.3.1 and Safari 16.4
-- VikingOSX, 2018-07-15, Apple Support Communities, No warranty expresed or implied

tell application "Safari" to activate
tell application "System Events"
	tell application process "Safari"
		set frontmost to true
		-- clear the cache
		keystroke "E" using {option down, command down}
		delay 1
		-- now clear all history
		tell menu item "Clear History…" of menu "Safari" of first menu bar to click
		delay 1
		tell pop up button 1 of sheet 1 of window 1
			perform action "AXPress"
			click menu item "all history" of its menu
		end tell
		tell button "Clear History" of sheet 1 of window 1 to click
	end tell
end tell
tell application "Safari" to if it is running then quit
return


22 replies
Question marked as Top-ranking reply

Apr 26, 2023 10:03 AM in response to svdrifter

I just tested the following AppleScript that I wrote in 2018 on macOS 13.3.1 and it still works to clear all history and the browser cache on Safari 16.4. You could save it first as AppleScript text (source) and then using option+Save As… as an Application that goes on your Dock. Then it is a one-button click solution to clear up Safari.


Open in the Script Editor, click compile, and run.


-- nohistory.applescript
-- Purges all Safari history, the browser cache, and quits the application if it is running.
-- Update: 2023-04-26, macOS 13.3.1 and Safari 16.4
-- VikingOSX, 2018-07-15, Apple Support Communities, No warranty expresed or implied

tell application "Safari" to activate
tell application "System Events"
	tell application process "Safari"
		set frontmost to true
		-- clear the cache
		keystroke "E" using {option down, command down}
		delay 1
		-- now clear all history
		tell menu item "Clear History…" of menu "Safari" of first menu bar to click
		delay 1
		tell pop up button 1 of sheet 1 of window 1
			perform action "AXPress"
			click menu item "all history" of its menu
		end tell
		tell button "Clear History" of sheet 1 of window 1 to click
	end tell
end tell
tell application "Safari" to if it is running then quit
return


Apr 21, 2023 10:42 AM in response to svdrifter

svdrifter wrote:

Does anyone know of a way to prevent Safari 16 (16.2) from caching history? The only option I can find is to set it to "one day". Of course, I can manually do a 3-click process to clear it after each query. But while this restriction might be acceptable for someone simply browsing the web, it's totally unacceptable for developing web code locally, using "Brackets" on a MAMP PRO local installation.

If Neil Armstrong was a programmer, he'd surely note: "Thats one small step for a man, one giant leap [backwards] for mankind."

Turn on private browsing to disable the cache.

Apr 29, 2023 9:02 AM in response to svdrifter

IMPORTANT UPDATE !


I'm adding this update in hopes that it might help others who have experienced the same issue.


The two most likely solutions were the "Clear History..." option within the main "Safari" top menu, and the "Empty Caches" option, halfway down the "Develop" top menu (if you happen to have loaded it). Neither options solves my issue.


The "Clear History..." option (in the "Safari" menu) does indeed "clear the history". It's really just an exact replication of the "Clear History..." option, in the "History" menu. (I'm not really sure why Apple duplicated an action in two different menus, but they did.)


I still haven't figured out what the "Empty Caches" option in the "Develop" menu is supposed to do... presumably it does clear some cache somewhere! But it does not seem to have any effect on the ability to refresh a page with just-changed coding, in order to display said changes. Unless someone happened to be "tweaking" styling code and/or content in a local development (like I was, in a local MAMP Pro installation), most would likely never notice whether it was [or was not] working as expected.


I've closely watched my personal "cache" directory (sorted in descending order, by date). I see a range of caches moving to the top of the sorted list, but nothing that would appear to be a likely option to be a solution, should I delete it from my user cache... so I didn't.


One thing that I did determine is that it takes far more effort to view changes in styles than changes in content. I suspect that changes only affecting the way things are displayed, are not nearly as likely to cause a clearing of the cache than changes affecting what is displayed.


It's unlikely that many will experience the same issues, unless they happen to be doing the same tweaks, while developing code. But, on the odd chance it might help someone else, I thought it worth the effort to make this update.


Thanks to those who made suggestions along the way!



Apr 26, 2023 7:15 AM in response to svdrifter

I'm currently redesigning an web application that I first built 22 years ago, that is designed to create a very lengthy PDF printout (typically 150-170 pages). It first requires a series of very complex mathematical calculations, from which it creates a very detailed report by piecing together thousands of paragraphs, images and other components, based on the calculations performed. No two reports are identical, unless they were both created using totally identical input!


I'm in the final process of working out the CSS for printing, which is similar to, but different from, the CSS for on-screen display. This typically requires making a few changes to the extensive stylesheet, then redisplaying the page - both onscreen and as "Print to PDF".


The problem I'm finding in Safari (and other browsers), running under Ventura, is that I can NOT efficiently clear the "History" and/or "Caches" in order for the changes to be viewed. The "Safari" menu has an option: "Clear History..", and the "Develop" menu has an option: "Empty Caches". Both of these work occasionally, but neither option works consistently, nor predictably. As such, I spend a couple of seconds modifying the CSS and several MINUTES trying to see the results. I sometimes "Clear History" and "Empty Caches" numerous times, without effect. I even tried closing the browser (and all opened support windows), which works once in a while, but again... consistently, nor predictably.


I'm about ready to throw this $3k MBP16 M1 computer (running under Ventura) in the trash and finish writing the app on my 2015 MBP15 (running under High Sierra). It actually runs just as quickly on that 8-yr-old (without the snafus). Unfortunately, I need to debug the app using the current version of Safari, which isn't possible on High Sierra.


I'm at my whit's end with this and cannot afford the continued delays.


CAN ANYONE GIVE ME A WAY TO EFFECTIVELY AND QUICKLY CLEAR THE HISTORY AND CACHES?


Apr 26, 2023 9:46 AM in response to Owl-53

Thank you. I am an application developer (40+ yrs on mainframe, Mac & WWW). I started on CPM and other OS, but moved to Apple when the all new "Apple IIe" was introduced. And I've used Safari's "Develop" menu since it's inception (whenever that was). It's indispensable, and one of the main reasons I only do my initial Web development on Safari.


I do thank you for the suggestion, however.

Apr 26, 2023 9:52 AM in response to Old Toad

Excellent suggestion... I use Keyboard Maestro extensively. I love it!


The problem, however, is that there's little point in creating a macro to accomplish a combination of keystrokes that don't do what they're supposed to do, when executed manually. I'll look at your macro in depth, to see if I'm missing something.


Many thanks for the suggestion!

Apr 26, 2023 10:45 AM in response to svdrifter

I would click OK on that warning dialog about Script Editor not allowed… and in Settings > Privacy & Security > Automation, I would enable Automator; and if Script Editor is there, enable System Events under it. If there is an entry for your particularly named Automator application, then see if you can enable System Events within its entry.


When I tested this, it was done outside of Automator or Shortcuts.

Apr 26, 2023 11:03 AM in response to VikingOSX

The only options I have in Settings > Privacy & Security > Automation are "BBEdit" and "VLC"... nothing else. I do have "Automator", but it does not appear under "Automation". For that matter, neither does "Keyboard Maestro", which seems strange.


I'm running under "Ventura 13.1" and "Safari 16.2". I've avoided updating, as each time I do, I just get more issues. I wish I had NEVER up[down]graded to Ventura!


Apr 26, 2023 12:05 PM in response to VikingOSX

Yes... same issue. I get a popup indicating "System Events got an error: Script Editor is not allowed assistive access." And in the ScriptEditor "Result pane", I get: "error System Events got an error: Script Editor is not allowed assistive access." number -1719 from menu bar 1 of application process "Safari"


I'm beginning to think this is an OS issue, rather than a Safari issue.


I've never had the impression that my "2020 M1 MBP16" running Ventura (or the original install of Monterey) is even the slightest bit faster than my "2015 Intel MBP15 running High Sierra" (if I did any extensive video processing, I might see a difference). Is it possible that the issue is with the OS, wherein "someone" tried to make the newer Macs appear to be faster than they actually are? Just a thought.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Safari 16 history caching

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.