Can you reduce the number of files in one?

I have JavaScript code split into several files, all using a module template (updating one global variable, like MyApp, with new features and members.

Is it possible to minimize files in one, and not spoil the area

Example. I want to reduce:

File1.js

var Module = (function(ns) { ns.fun1 = function() { alert('fun1'); }; return ns; })(Module || {}); 

File2.js

 var Module = (function(ns) { ns.fun2 = function() { alert('fun2'); }; return ns; })(Module || {}); 
+6
source share
2 answers

Yes, you can, and this is a good way to work, for everyone, especially if it’s involved for developers and great for developers.

I am using the Minify class ( http://code.google.com/p/minify/ ) with a special configuration file ( https://beat.snipt.net/minify-config-file-minify-each-folder-from-project -1-minified-file / ), which scans my folders and makes a file (JS or CSS) for each subfolder. That way I can create modular JS or CSS files that can be divided into classes or regular files.

The key is the ORDER of files, depending on the functions of the read folder and the type of OS may differ (ex php readdir vs scandir)

+1
source

The global scope is actually global because it does not matter if you change it from one file or several files. However, the order of your files may matter, depending on the module template template you are using. For a good entry, also covering cross file personal state, read the following: http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth

+2
source

All Articles