I have seen Scriptaculous.js file to include its required javascript files dynamically. Is there any better approach to include javascript dynamically.
For example,
document.getElementsByTagName("head")[0].appendChild(fileref) is not working if you have some document.ready() works inline. $("head").append(fileref); works great for me, although it needs jquery.min.js inline reference.
and master_load.js :
function loadjscssfile(filename) {
if (filename.substr(filename.length - 4) == ".css") { // 'endsWith' is not IE supported.
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("href", filename)
//fileref.setAttribute("type", "text/css")
}
else if (filename.substr(filename.length - 3) == ".js") {
var fileref = document.createElement('script')
fileref.setAttribute("src", filename)
//fileref.setAttribute("type", "text/javascript")
}
$("head").append(fileref);
}
function load_master_css() {
loadjscssfile("css/bootstrap.min.css");
// bunch of css files
}
function load_master_js() {
loadjscssfile("script/bootstrap.min.js");
// bunch of js files
}