MoLoCo stands for Module Loader Component. A small piece of script, aimed to automate the process of loading and injection of external snippets (or components) and the needed dependencies in a static page where you cannot add it by yourself.
It can load JS scripts and CSS styles with ease.
MoLoCo was created to supply the need of injecting dynamic content in an environment where the pages are static and generated by a CMS in which we have no control.
MoLoCo looks in the current page for a specific hidden element and loads synchronously the module(s) listed in the value attribute of this element (comma separated)
To use MoLoCo, just put a and include the moloco.js script in your page.
MoLoCo will then, look for the files named yourmodule.js, module2.js and snippet3.js in the modules subfolder and load them synchronously.
A module is a simple javascript file that tells MoLoCo what files to load, in which order and under which condition.
MoLoCo uses the same syntax of loaderr (in fact it is an automated version of loaderr)
var styles = [
"/static/css/my_snipet/main.css" ,
"/static/css/dist/some_lib/some_lib_style.css"
],
scripts = [
["/static/js/dist/jquery-1.10.2.min.js", !window.jQuery ],
["/static/js/dist/underscore-1.5.1.min.js", !window._ ],
"/static/js/dist/some_mobile_detection_lib_or_routine.js", /* no condition, it is always loaded */
["/static/js/my_libs/my_utils.js", !window.myUtils ],
"/static/js/my_snipet/main.js", /* no condition, it is always loaded */
[ "/static/js/my_snipet/mobile_specific.js", window.isMobile ], /* loads only if mobile */
];
moloco.loadStyles(styles, function() {
/* loadStyles callback */
moloco.loadScripts(scripts, function(){
/* loadScripts callback */
/* at this point all dependecies are already loaded and you can safely start your application */
mySnippet.init();
});
});
For a complete description and examples check the loaderr documentation.
To see MoLoCo in action check the demo page.
Use it as you wish. I would greatly appreciate if you keep the credits though.
MoLoCo is made by Renato Rodrigues and shared with you for free. Enjoy it!