Safari 3: Onload firing, and bad timing

Written by on June 15th, 2007 in Ajax News.

Mark Wilton-Jones has written up a detailed article on the behaviour and speed of Safari 3 in which he dives into how Safari fires onload at a different time than most other browsers, and other implementation details that mean that you can’t trust JavaScript in the page to do any benchmarking.

In Safari, it seems onload fires before the page has been displayed, before layout has been calculated, before any costly reflows have taken place. It fires before images have completed loading (this can also happen in rare cases in Opera, but Safari seems to do it everywhere), meaning that a substantial part of the load time is not included. So basically, onload is not trustworthy in Safari for checking page loading times.

It is possible to force Safari to layout the page before checking for the time. To do this, check for the offset values of any element, such as the offsetWidth of the body:

window.onload = function () {
var ignoreMe = document.body.offsetWidth;
var endTime = new Date();
};

Note, however, that this still does not include actually displaying the page, only calculating what will be displayed, so it is not perfect, but it does make it slightly closer to the behaviour of other browsers.

Mark finishes up talking about how to better benchmark the performance, and concluding that this doesn’t mean Safari is slow (it is clearly far from it), but it may not be as fast as it claims on TV :)

Source: Ajaxian
Original Article: http://ajaxian.com/archives/safari-3-onload-firing-and-bad-timing

Leave a Reply

You must be logged in to post a comment.



Site Navigation