I use jQuery on my website like this:
<head>
<script src="http://ajax.googleapis.com/.../jquery.min.js" ...></script>
</head>
I then use:
$(document).ready(function(){
});
On some occasions, this event is used:
$(document).ready(function(){
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "http://www.script-host.com/.../script.js";
document.getElementsByTagName("head")[0].appendChild(s);
});
Now jquery.js seems to be (one of) the heaviest resource on my website in terms of filesize. I therefore want to lazy load jquery.js itself but I understand that this would cause all document.ready events to fail. What is the best workaround for this?
Maybe this recent article may help you: http://samsaffron.com/archive/2012/02/17/stop-paying-your-jquery-tax
the idea behind is to create a temporary
$function in which you collect all function to be executed atdomreadyevent and then it’s replaced later when you load jQuery at the bottom of the page.