Loading jquery core asynchronously with backup

With performance optimizations and non-blocking scripts in the header, I'm trying to asynchronously load jquery itself.

I came across a jQuery Loader script that async loads jquery and after that catches and queues jquery document ready calls. This seems to work most of the time, but not always.

So, I created a backup to load the local version of jquery, if the bootloader did not finish within x seconds. Backup work, but not completely. Some parts may work, others not.

Script is still being called in the header after loading the jquery script bootloader:

<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 who has experience with jQuery Loader (jQl) that can help resolve the issue that it fails regularly?

  • , , , , js , ?

  • jquery / script/ .

, jQuery, jquery , , jquery, - .

+4
2

jQuery CDN, .

,

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript"> window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"></script>')</script>
<script type="text/javascript" src="scripts.js"></scripts>

from jQuery Javascript jQuery

jQuery , , , Firebug ( Net)

0

jquery, -, !

.

function loadScripts(urls, length, success){
    if(length > 0){
        script = document.createElement("SCRIPT");
        script.src = urls[length-1];
        console.log();
        script.onload = function() {
            console.log('%c Script: ' + urls[length-1] + ' loaded!', 'color: #4CAF50');
            loadScripts(urls, length-1, success);               
        };
        document.getElementsByTagName("head")[0].appendChild(script);
    }
    else
        if(success)
            success();
}

SCRIPTS

urls = ['https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js',
    'https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js',
    'http://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'
    ];

loadScripts(urls, urls.length, function(){
    /* Do something here after loading all script */

});

!

0

Source: https://habr.com/ru/post/1527903/


All Articles