Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Large background image load time is holding up my onLoad function

I have a beautiful background image on a website which unfortunately takes a while to load. The rest of my page is driven by a function that is called when the body loads like so:

<body onLoad="initialise()">
      ...

Because of this, my browser is waiting for the background to fully load before calling initialise(). How can i either call initialise() before the page fully loads or at least before the background image does.

Thank you for your time :)

like image 327
user1055650 Avatar asked Aug 14 '26 09:08

user1055650


2 Answers

Just add this right before the </body> tag:

<script type="text/javascript">initialise();</script>
like image 64
Niet the Dark Absol Avatar answered Aug 17 '26 01:08

Niet the Dark Absol


If you need to wait til the page is ready, try using jQuery's ready event instead:

<script type='text/javascript'>jQuery(document).ready(initialise)</script>

This will run before images are loaded, but will wait for all HTML.

like image 30
kitti Avatar answered Aug 17 '26 01:08

kitti