Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have this annoying problem with Safari 6, each time I go back or forward (both the toolbar buttons or two singer swipe) the tab refreshes. Here is a quick video to illustrate the problem: https://dl.dropbox.com/u/3257155/safari-refresh.mov

Normally I wouldn't really mind, it kinda grown on me over time (I'm not really sure this started when I updated to Safari 6 or to Mountain Lion - there was about a week between the updates), but my client found a bug in the web app I build (some buttons stop responding when he goes back - he is still on Lion) and I can't reproduce the problem because my Safari refreshed every time.

So my question is, what is the normal behavior for Safari? And how/if can I make Safari not refresh?

UPDATE

Turns out the problem was that Safari doesn't (by default) fire the onLoad even when on the "back action". I couldn't reproduce the bug on my machine because apparently the 1password extension causes the onLoad event even when you go back.

share|improve this question
    
have you disabled caches in Safari? I just tested the same thing with Safari 6 on ML, and it doesn't refresh the page under normal conditions, i.e. it servers the cached version within the normal cache-control parameters –  Stu Wilson Sep 6 '12 at 12:43
    
No I haven't disabled the caches (from the Develop menu or otherwise) –  Dan F. Sep 6 '12 at 12:59
    
Post your update as an answer and accept it, its interesting enough to be helpful to someone else in the future. –  Stu Wilson Sep 10 '12 at 19:30
    
Ok Stu I did. Thanks. –  Dan F. Sep 13 '12 at 9:02
    
I don’t have 1password on my machine and the problem still exists. :( –  mcb Dec 7 '12 at 0:01

2 Answers 2

While visually it looks like the page is refreshing, if the original response had the appropriate cache headers, it will be served from the cache and no request is made to the server until the cache is stale.

While testing this I did ran into a problem where Safari's Web Inspector does not seem to properly indicate wether a page was loaded from the cache, but while monitoring my server logs it appeared that Safari is respecting the cache headers being sent back after all.

When a server sent headers which disallow caching with the response, or the cache has expired in the meanwhile, Safari just like any other browser will make a new request when revisiting a page from the history.

Also note that you can completely disable caching from the Develop menu (if enabled). Make sure you did not enable this option.

enter image description here

share|improve this answer
    
Caches are automatically re-enabled on restart of Safari, so unless he never closes Safari it won't be the root cause. –  Stu Wilson Sep 6 '12 at 12:57
up vote 2 down vote accepted

Turns out the problem was that Safari doesn't (by default) fire the onLoad even when the "back action" is performed (using the back button or the two finger swipe) but I couldn't reproduce the bug on my machine because apparently the 1password extension causes the onLoad event even when you go back.


Further explications at Render's request:

So let's assume this code on all pages:

$(document).ready(function () {
    alert('test');
}

And this sequence of actions:

  1. open page-1.html
  2. open page-2.html
  3. Go back
  4. Go forward

Safari won't show the alert after step 3 and 4, so I the onLoad event is not fired and the page .js continues the execution from where it left off when you navigated away from the page.

Also in the current version 6.0.3, having 1password extension (3.9.14) seems to have no effect over this behavior.

Hope that helps. This shouldn't matter in most cases, it's only when you write bad code (like it did) it will bit you in the arse :)

share|improve this answer
    
What do you mean ? That didn't make sense to me, can you please elaborate ? –  Render Apr 21 '13 at 19:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.