Reputation: 417
I'm current using a javascript with the this tag
<body onload="javascript:Mine();">
Now i noticed that it is taking some time to load this function after i open the page.So is there any other way i can reduce this delay ?
Thanks
Upvotes: 2
Views: 2524
Reputation: 943547
onload
fires when a page is completely loaded. To get things to fire sooner you can either:
onload
domready
event<script>
directly (instead of assigning an event handler)Upvotes: 6
Reputation: 129792
OnLoad
waits for all images and other external resources to be completely loaded. If you only want to know that the entire DOM tree with all HTML elements have been loaded, use OnDOMReady
.
Note that this is not a trivial task if you want it to work well across many browsers. If you're using jQuery, then they've solved the problem for you, and you can write:
$(document).ready(function() {
Mine();
});
But if not, loading jQuery only for that feature might not improve your page load at all. Another solution, then, would be to put the call just before </body>
:
<body>
...
<script type="text/javascript">Mine();</script>
</body>
Most of your DOM tree should be available to you at that point, so that might be a way to go.
Upvotes: 4
Reputation: 1739
Obvious answer: Speed up your page load.
onLoad means, that function will be run after your whole page has finished loading.
Upvotes: 0