It's a shame pageshow is fired always after load event, otherwise it would
have been simple to manage this case.

One thing could make sense is to bind "unload" after "onload".

First of all bfcache will not work if the onload event did not fire ( page
not completely loaded, no state and cache saved )

Secondly and logically speaking, unload event is not fired if load one has
not completed.

Try out:

<?php
function write($what){
    echo    $what, ob_get_clean();
    @ob_flush();
    @flush();
}
ob_start();
write(str_repeat(" ", 1024 * 8));
sleep(1);
?>
<script type="text/javascript">
onload = function(){
    alert("onload");
};
onunload = function(){
    alert("onunload");
};
document.write("onunload is present " + onunload + "<br />");
</script>
<?php
write('3');
sleep(3);
write('2');
sleep(3);
write('1');
sleep(3);
?>

and try to change url before 1 is showed and other 3 seconds have gone ...
no onunload event is fired.

Accordingly, since unload does not make sense before load is fired, we can
simply use that bfcache check and move this block inside the generic onload
event.

Above code should go here:

// A fallback to window.onload, that will always work
jQuery.event.add( window, "load", function(){
    // check if pageshow was defined
    var onpageshow = typeof window.onpageshow === 'function';
    if(!onpageshow)
        // if not set as body attribute (body will be always present here)
        document.body.setAttribute('onpageshow', 'return;');
    // if this check is true bfcache should not be possible
    if(typeof window.onpageshow !== 'function')
        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 );
                }
            }
        });
    // if onpageshow was not there we remove onpageshow attribute
    else if(!onpageshow)
        document.body.removeAttribute('onpageshow');
    jQuery.ready();
});

But before John should decide about the other patch I suggested for "ready
stack", after that I could implement this as well without problems.

Regards



On Wed, Jul 29, 2009 at 11:33 AM, James Padolsey <
jamespadol...@googlemail.com> wrote:

>
> Good idea Mark!
>
> This seems to work:
>
> jQuery.support.bfCache = (function(){
>    document.body.setAttribute('onpageshow', 'return;');
>    return typeof window.onpageshow === 'function';
> })();
>
> Event detection technique from
>
> http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
>
> On 29 July, 11:14, Mark Gibson <jollyt...@gmail.com> wrote:
> > Maybe you could approach this from the other side,
> > ie. don't add the "unload" handler if bfcache is available.
> > You could probably use the pageshow or pagehide events to detect this.
> >
> > -- Mark
> >
> > 2009/7/29 James Padolsey <jamespadol...@googlemail.com>:
> >
> >
> >
> > > Around line ~3100 (3321 in the latest nightly) you're binding the
> > > unload event so as to prevent any memory leaks in our favourite
> > > browser (IE). Unfortunately the presence of an "unload" handler
> > > disables some caching techniques used in other browsers (see
> > >https://developer.mozilla.org/En/Using_Firefox_1.5_caching...
> > > Specifically the "bfcache").
> >
> > > I know you're no longer using browser detection so I was wondering, is
> > > there an easy and quick way to detect a browser that's going to leak
> > > memory? ... If so, you could conditionally add the "unload" handler,
> > > only for browsers that require it (IE)...
> >
> > > If there's no way of testing it then why can't you just use some
> > > browser detection there? Is the cost of disabling the bfcache really
> > > worth the benefit of having no browser detection in the core?
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to