firebugでのデバッグとかに使うようになってきたのでメモ。
読み込み順序は保証されないので注意。
jsの読み込み
(function(items){
var head = document.getElementsByTagName("head")[0];
for(var i = 0, len = items.length; i < len; i++) {
var script = document.createElement("script");
script.src = items[i].src;
script.type = "text/javascript";
if(items[i].charset) {
script.charset = items[i].charset;
}
head.insertBefore(script, head.firstChild);
}
}([
//{ src: "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" }, //jquery google
//{ src: "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js" }, //jquery ms
//{ src: "http://code.jquery.com/jquery-1.7.1.min.js" }, //jquery cdn
//{ src: "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" }, //jqueryUI cdn
//{ src: "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" }, //swfobject 2.2
{ src: "hoge.js" },
{ src: "fuga.js", charset: "shift-jis" }
]));
cssの読み込み
(function (items) {
var head = document.getElementsByTagName("head")[0];
for(var i = 0, len = items.length; i < len; i++) {
var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = items[i];
head.insertBefore(link, head.firstChild);
}
}([
//"http://yui.yahooapis.com/2.9.0/build/reset/reset-min.css", //reset-min
//"http://yui.yahooapis.com/2.9.0/build/fonts/fonts-min.css", //fonts-min
"/css/hoge.css",
"/css/fuga.css"
]));