In the development of Web projects, JS,CSS files will become more and more with the development of the project, which brings some problems to the performance, such as the more JS,CSS the page introduced, then to increase the number of HTTP requests, a good way to solve the problem is to merge JS, CSS file.
Here is a simple introduction to a method, very simple. The following is an example of merging JS files
(1) g.js file
Copy Code code as follows:
~function () {
Window. g={};
g.method={
Add:function () {alert (111);}
, Sub:function () {alert ("subtraction");}
};
}();
(2) t.js file
Copy Code code as follows:
var t= (function () {
return {
T1:function () {alert ("T1 method!")}
, T2:function () {alert ("T2 Method!")}
, Sum:function (obj) {return obj.x+obj.y}
};
}());
Listed above a simple JS file, the following will be written a batch file to merge the above files
(3) A batch method for merging Js,css files, with a filename assumed to be named Debug.bat
Copy Code code as follows:
Copy g.js+t.js gt_bin.js/b
Description:
(1) Enter the JS file to be merged, save Debug.bat file, run Debug.bat.
(2) on such a line of code is done, very simple, gt_bin.js for the merged file name,/b is a fixed parameter, the file merged, the page will only refer to the gt_bin.js can be, thereby reducing the JS file reference, to reduce the number of HTTP requests, Improve the performance of the site.
(3) The same is true for merging CSS file methods.