minify - Developing javascript for minification -
I have read many answers but I am thinking the best way to get the following -
I have a commission to provide a widget-type javascript tool where my client will include the script, give a div an id and the widget will take care of loading itself.
So far, in development I have divided the widget into many files for uniformity (as the client wants to change the source code and repeat it again). I connected to the script tag $. To check the load and callback methods like mechanisms, check whether the library exists or not, and if they are not included
I maintain this functionality and consistency, while at the same time Provide for minification in? I think this objective is defeated in 6 or 7 smaller files, but if I have to include several libraries in my argument and link to other source files, of course I just can not reduce it in one file ?
Your LIbs should be pre-minified, or available in the same way, and your app is a The object should stay in singles. Generally:
FILE-BOOTSTRAP
// Create global "extension" method var extension = function (obj, extObj) {if (arguments.length & gt; 2) {for (var an = 1; a & lt; arguments.length; a ++) {extension (obj, argument [a]); }} Else {for (extObj in var i) {obj [i] = extObj [i]; }} Return obj; };
file-A
window.APP = window.APP || {}; Extension (window.APP, {// subsystem A functionality subsystem A: {}});
FILE-B
window.APP = window.APP || {}; Extension (window.APP, {// subsystem B functionality subsystem B: {}});
file-z
window.APP.boot ();
Then you simply press and minify the files. If you have a bunch of functions / classes in the Global, then you have to make your complete mess in the self-execution function before minimizing.
Comments
Post a Comment