Merge and compress your JS when the project is built

Source: Internet
Author: User

For website optimization, the combination of compression JS, CSS and other static content is one of the required courses, a can save bandwidth, two can reduce the HTTP request, and three speed up the site's access speed

For how to implement merge compression JS

Scheme one: Inherit IHttpModule, intercept HTTP, then get its <script src=*> tag, remove the JS file to merge into a resource file

Scenario Two: If you're using the Web solution for ASP. NET MVC 4, then of course you can use bundle technology.

Scenario Three: Do not rely on any server technology, local first merge compression before uploading

This paper focuses on the program three

To merge files, you can use the Copy command under DOS

1 copy jquery.min.js+jquery-migrate-1.1. 1. js+jquery.hoverintent.minified.js+validform_v5. 3.1. Js+jquery.cookie.js+the7.pw.js index.js/b

To compress the JS file, the UGLIFYJS is used here. For how to install UGLIFYJS, you can refer to this article

DOS commands are as follows

1 uglifyjs index.js-m-o index.min.js

In order to compress a JS, every time into the DOS clever code, is not the way ah, so you can build a bat file in the JS directory, each time to upload a point before the finished.

But that's enough, for lazy people like the program ape, the point is superfluous.

So can we use the pre-event generated by the project to invoke the bat file is not better?

In this way, each time the project is generated, the merged compressed version of JS, not beautiful

Finally in the page, we can directly refer to the compressed version of JS

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.