Multiple JS and CSS file Merging method detailed description _javascript Tips

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.