At the beginning of a project, there is usually only one JS file except libraries such as jquery.
However, as the number of functions increasesCodeIt will also continue to expand. When more than a certain degree (more than 500 lines), the Maintenance difficulty will be greatly increased. The organizational logic is chaotic. It is difficult to quickly locate the desired location during debugging, and it is difficult to choose the insert location when writing a new function. Rolling around in a long JS file all day is a headache.
An optional solution is to use dependent libraries, such as requirejs, seajs, And in. js. However, more code needs to be introduced, and additional HTTP requests need to be added to maintain dependency.
In most cases, JS Code does not expand to the point where dependent libraries must be introduced. Is there a way to perform fine-grained maintenance on JS Code without adding new code and HTTP requests?
In the current project, the JS Code after excluding jquery and other class libraries is about KB (58kb after compression). We use this solution:
1. Split JS into multiple files by module or by nature, for example, extract user-related parts into user. JS, and extract the shared methods into helpers. js.
2. Write sh script (Linux) or bat script (Windows) Merge all JS into all. JS, and call yuicompressor for compression to generate a all-min.js.
//Bat script in WindowsDelAll. js all-min.JSTypeSource \ *. js> All.Jsjava-jar YC. Jar -- preserve-semi-O all-min.js all. js
3, in the development environment using all. js (convenient DEUG), production environment using all-min.js.