In the development of Web projects, js and css files will become larger and larger with the development of projects, which brings some performance problems, such as js introduced by pages, the more css, the higher the number of http requests. A good solution to this problem is to merge js and css files.
The following describes a simple method. The following describes how to merge js files.
(1) G. js File
Copy codeThe Code is as follows:
~ Function (){
Window. G = {};
G. Method = {
Add: function () {alert (111 );}
, Sub: function () {alert ("subtraction ");}
};
}();
(2) T. js File
Copy codeThe Code is as follows:
Var T = (function (){
Return {
T1: function () {alert ("t1 method! ")}
, T2: function () {alert ("t2 method! ")}
, Sum: function (obj) {return obj. x + obj. y ;}
};
}());
A simple js file is listed above. Next we need to write a batch file to merge the above files.
(3) Merge js and css files in batches. Assume the file name is named debug. bat.
Copy codeThe Code is as follows:
Copy G. js + T. js GT_bin.js/B
Description:
(1) enter the js file to be merged, save the debug. bat file, and run debug. bat.
(2) This is just a line of code. It is very simple. GT_bin.js is the name of the merged file./B is a fixed parameter. After the file is merged, only GT_bin.js can be referenced on the page, which reduces the number of js file references, reduces the number of http requests, and improves the website performance.
(3) The same is true for merging css files.