(function() {
    if(typeof(jQuery) == 'undefined') {
        window.jQuery = 'loading';
        var jq = document.createElement('script');
        jq.type = 'text/javascript';
        jq.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js';
        jq.onload = function() {
            console.log('jQuery ' + jQuery.fn.jquery + ' loaded successfully.');
        };
        jq.onerror = function () {
            delete jQuery;
            alert('Error while loading jQuery!');
        };
        document.getElementsByTagName('head')[0].appendChild(jq);
    } else {
        if (typeof (jQuery) == 'function') {
            alert('jQuery (' + jQuery.fn.jquery + ') is already loaded!');
        } else {
            alert('jQuery is already loading...');
        }
    }
})()