Loading jQuery on window.onload?
i would like to load jquery.js after the window.onload event has been fired by browser (reducing load time)
Doing that maybe with appendChild the problem is i can't use anymore $(document).ready();
Is there a way to use something 开发者_如何学JAVAequivalent to .ready after the loading of jQuery (after the window.onload?)
thanks
Just place <script>
s at the bottom of your HTML files. If you load jQuery right before the closing </body>
tag, page rendering isn’t blocked while jQuery is loading.
It doesn’t matter if you speed up window.onload
if you’re not gonna use it anyway. E.g. if you use…
$(document).ready(function() {
// …
});
…or its shorter alias…
$(function() {
// …
});
…internally it’s not relying on window.onload
, but on DOMContentLoaded
.
Loading scripts at the bottom is gonna help you much more than waiting for window.onload
to start loading your scripts.
I think you can't. In order to use jquery as well as other plugins that developed from jquery, you have to load jquery.js first of all. (in the part, you have to put the script that load jquery.js on top)
It doesn't even work if you load (Slider, Thickbox, DatePicker...) first then jquery.js
^^
first of all load jquery from here
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
loading it from google means the user most likley already has it cached resulting in a much quicker load.
also to be honest jquery isnt that big a file (less than a meg) so it shouldnt really affect load times.
all script tags should be at the bottom of your page in anycase.. so loading times wont be affected.
content
script tags
otherwise you could do something like
if ($.jquery){ document.body. and then my js gets rusty... but basicaly append the script tag
精彩评论