With performance optimization and non-blocking scripts in header, I've been trying to asynchronously load the jquery itself.
I ran into a jQuery Loader script, that async loads jquery and thereafter catches and queues jquery document ready calls. This seems to work most of the time, but not always.
So I created a fallback to load a local jquery version if the loader hasn't finished within x seconds. The fallback works, but not completely. Some parts may work, others not.
Script so far called in head, after loading the jquery loader script:
<script type="text/javascript">
function loadScript(url)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
}
var fallback_timer = setTimeout(function() {
loadScript('/path/to/local/js/jquery.js');
},5000);
jQl.loadjQ('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',function({clearTimeout(fallback_timer);});
</script>
Questions:
Anyone with experience with jQuery Loader (jQl) that can help out fixing the issue that it fails regularly?
Anyone who can tell me why, incase of failure, only some of my other js scripts work, but some keep failing?
I am very open to asynchronously loading jquery core with some other plugin/script/direction to look for.
To clarify, I am not looking at asynchronously loading scripts using jQuery, but loading the jquery itself asynchronously while supporting loading jquery dependent scripts somewhere down the road.