4 ms·
If all you need is an easy way to asynchronous / lazy load JavaScript, you can just include something like this: http://friendlybit.com/js/lazy-loading-asyncron
by philfreo 16y ago
If all you need is an easy way to asynchronous / lazy load JavaScript, you can just include something like this: http://friendlybit.com/js/lazy-loading-asyncronous-javascript/ http://friendlybit.com/js/lazy-loading-asyncronous-javascrip...
Or a nice function, with "Ready" support:
In <head>:
<script type='text/javascript'>
function ljs(s){
var a=document.createElement('script'),
b=document.getElementsByTagName('script')[0];
a.type='text/javascript';
a.async=true;
a.src=s;
b.parentNode.insertBefore(a,b)
}
var Ready=[];
</script>
Then anywhere in the <body> or in any included scripts you can do:
Ready.push(function() {
//this will get executed after all the ljs files
});
Then in a script that contains your JS library, append:
$.ready(function() { // or some other ondomready fn
// execute all the Ready functions
for (var i = 0, m = Ready.length; i < m; i++) {
Ready[i]();
}
delete Ready;
});
- deleted 16y ago[deleted]