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; A good way to solve this problem is to merge JavaScript files. If you need to know about css files, you can refer to the development of Web projects. js and css files will become more and more popular with the development of projects, this poses performance problems. For example, if the js and css introduced by pages are more, the number of http requests is increased, A good way to solve 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
The Code is as follows:
~ Function (){
Window. G = {};
G. Method = {
Add: function () {alert (111 );}
, Sub: function () {alert ("subtraction ");}
};
}();
(2) T. js File
The 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.
The 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.