<head>
<script> addResourse("jQuery.js"); </script>
</head>
<body>
....
<script>console.log(jQuery);</script>
</body>
function addResourse(path){
var compile = document.createElement("script");
compile.type = "text/javascript"; compile.src = path; compile.async = false;
document.head.appendChild(compile);
}
function loadjscssfile(filename, filetype, callback){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("async",true)
fileref.setAttribute("src", filename)
if (fileref.readyState) { //IE
fileref.onreadystatechange = function () {
if (fileref.readyState == "loaded" || fileref.readyState == "complete") {
fileref.onreadystatechange = null;
callback();
}
};
} else { //Others
fileref.onload = function () {
callback();
};
}
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(fileref);
}
(function (){
//Dynamically load jquery
if (typeof jQuery == 'undefined') {
loadjscssfile('//code.jquery.com/jquery.min.js','js',function () {
main();
});
} else main();
})();
function main(){
$(document).ready(function(){
//main code.....
});
};
function jQueryWaiting() {
if (typeof jQuery === "undefined") {
setTimeout(jQueryWaiting,100);
return;
}
$(document).ready(function(){
console.log( "ready!" );
});
}
jQueryWaiting();