Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created November 5, 2011 18:56
Show Gist options
  • Save 3rd-Eden/1341882 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/1341882 to your computer and use it in GitHub Desktop.
custom script loader
(function (global) {
var _namespace = global.namespace
, namespace = {};
namespace.push = function push (fn) {
return fn && typeof fn === 'function' && fn(namespace);
};
if (_namespace && _namespace.length) {
var i = _namespace.length;
while (i--) namespace.push(_namespace[i]);
}
}(this))
(function (a, b, c, d, e, f){
for (d = c.length, f = a.getElementsByTagName(b)[0]; d--;) {
e = a.createElement(b);
e.src = c[d];
f.parentNode.insertBefore(e, f);
}
})(
document
, 'script'
, [
'http://cdn.example.com/core.js'
, 'http://cdn2.example.org/page.js'
]
)
('namespace' in this ? namespace : (namespace = [])).push(function push (namespace) {
});
@tblobaum
Copy link

tblobaum commented Nov 6, 2011

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment