A simple Zero Dependency, dependency management framework
Many JavaScript web dependency frameworks require you to have the framework loaded before doing ANYTHING. This framework and "method" does not require code to be run in ANY particular order. That means you could have this library loaded last and still have everything run in the right order.
- This is particularly useful if you simply concatenate and minify JS files together without regard for ordering.
- Also useful if you have no control of where and when JS code runs.
- Many large organizations have lots of different groups that edit and maintain different parts of a page. This approach helps unify JS into a common framework slowly over time.
Download and place the ZeroDep JavaScript library somewhere accessible via the web.
All dependencies and code requiring dependencies will be run after ZeroDep has run (code can of course be placed and loaded before). So if you want code to run in the HEAD html tag ZeroDep needs to load and run in the HEAD html tag.
Via HTML Script tag
<script src="zerodep.js"></script>
OR
<script src="zerodep.js" async></script>
OR
Copy and paste the code into your script files or inline it in a script block in the HTML
(window.ZDQ = window.ZDQ || []).push(function(zd) {
zd.def("NameOfDependency", function() {
return "ArgumentToExpose";
});
});
OR (if you know the ZeroDep lib has loaded)
zd.def("NameOfDependency", function() {
return "ArgumentToExpose";
});
(window.ZDQ = window.ZDQ || []).push(function(zd) {
zd.req("Dependency", function(fromDefine) {
//Do your stuff
});
});
Requiring multiple dependencies
(window.ZDQ = window.ZDQ || []).push(function(zd) {
zd.req(["Dependency1","Dependency2"], function(fromDep1, fromDep2) {
//Do your stuff
});
});
OR (if you know the ZeroDep lib has loaded)
zd.req("Dependency", function(fromDefine) {
//Do your stuff
});
Requiring multiple dependencies
zd.req(["Dependency1","Dependency2"], function(fromDep1, fromDep2) {
//Do your stuff
});
(window.ZDQ = window.ZDQ || []).push(function(zd) {
zd.reqDef("RequiredDep", "NewDepName", function(FromRequiredDep) {
//Do your stuff
return "NewDepArgumentToExpose";
});
});
Requiring multiple dependencies
(window.ZDQ = window.ZDQ || []).push(function(zd) {
zd.reqDef(["RequiredDep1", "RequiredDep2"], "NewDepName", function(FromRequiredDep1, FromRequiredDep2) {
//Do your stuff
return "NewDepArgumentToExpose";
});
});
OR (if you know the ZeroDep lib has loaded)
zd.reqDef("RequiredDep", "NewDepName", function(FromRequiredDep) {
//Do your stuff
return "NewDepArgumentToExpose";
});
Requiring multiple dependencies
zd.reqDef(["RequiredDep1", "RequiredDep2"], "NewDepName", function(FromRequiredDep1, FromRequiredDep2) {
//Do your stuff
return "NewDepArgumentToExpose";
});