Side navigation
#5198 closed bug (fixed)
Opened September 10, 2009 10:20AM UTC
Closed September 14, 2009 09:28PM UTC
Last modified March 15, 2012 11:25AM UTC
ready functions being triggered (accidentally?) on 'Back' button
Reported by: | candlerb | Owned by: | brandon |
---|---|---|---|
Priority: | minor | Milestone: | 1.4 |
Component: | event | Version: | 1.3.2 |
Keywords: | ready event onload unload AJAX back | Cc: | |
Blocked by: | Blocking: |
Description
I get the following behaviour on both Firefox 3.0.13 and Opera 9.63 under Ubuntu Hardy.
When you hit the 'back' button on your browser, any jQuery.ready and document.onload functions are retriggered. This could cause, for example, page components to be refetched via AJAX.
The cause of the problem seems to be this bit of jQuery:
// Prevent memory leaks in IE // And prevent errors on refresh with events like mouseover in other browsers // Window isn't included so as not to unbind existing unload events jQuery( window ).bind( 'unload', function(){ for ( var id in jQuery.cache ) // Skip the window if ( id != 1 && jQuery.cache[ id ].handle ) jQuery.event.remove( jQuery.cache[ id ].handle.elem ); });
That is - if you comment this out, behaviour reverts to expected. Pressing 'back' just shows the page how it was, and doesn't trigger the window.onload function.
However I don't know why binding an 'unload' handler would cause the behaviour of the 'back' button to change in this way.
Fixing this would (I believe) improve the client experience: the browser 'back' button would work more rapidly, and in some apps there would be less server load caused by unnecessary AJAX calls to fetch page fragments.
OTOH, it's possible that some people are actually relying on this behaviour. If so I think it should be made explicit, as it seems to be something of an accidental side-effect at present.
I'll attach a couple of pages which demonstrate the problem. Note that I'm not actually calling any jQuery functions in page1.html - just loading the jQuery framework itself.