I recently had an issue where a third-party image was timing out (after 30 seconds!) and it was making the rest of the site unusable due to the fact an effects plugin was waiting for this event to show certain elements on the page. I got around this by triggering the event after five seconds. Here’s my code (requires jQuery):
window.loadedHandlerCalled = false;
$(window).on('load', function() {
window.loadedHandlerCalled = true;
});
setTimeout(function() {
if (window.loadedHandlerCalled === false) {
window.dispatchEvent(new Event('load'));
}
}, 5000);
If the window loads in under five seconds things execute as normal. Starting the effects without some of the images is preferable to the user having to wait ages and closing the tab down.
Tim Bennett is a Leeds-based web designer from Yorkshire. He has a First Class Honours degree in Computing from
Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.