M
M
Misha72014-08-24 20:17:13
JavaScript
Misha7, 2014-08-24 20:17:13

How does load jquery work?

I want to make an application for smart tv. I read that jquery is better not to use. TV resources are small. In the application, I thought to use the load jquery method. Is it possible to do something similar without jquery, in pure javascript?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Bazykin, 2014-08-24
@FAT

var loadScript = function(src, callback, appendTo) {
    var script = document.createElement('script');

    if (!appendTo) {
        appendTo = document.getElementsByTagName('head')[0];
    }

    if (script.readyState && !script.onload) {
        // IE, Opera
        script.onreadystatechange = function() {
            if (script.readyState == "loaded" || script.readyState == "complete") {
                script.onreadystatechange = null;
                callback();
            }
        }
    }
    else {
        // Rest
        script.onload = callback;
    }

    script.src = src;
    appendTo.appendChild(script);
}

Or use something like RequireJS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question