. NET using Yui-related DLL compression JS (according to their own rules, think all feel strong and interesting)

Source: Internet
Author: User

Write in front

Whether it is to do the front-end or do the backstage, whether it is to understand JavaScript or do not understand JavaScript, I would like to have or more or want to know a little bit of JS compression for the effect of page performance improvement.

Before old like to use online compression tool to compress JS, in fact, think of this practice before a little shudder, suppose, if a project JS has 50, you want to use the online compression tool compression JS50 times it? Just publish it once and compress it 50 times, it's not the time to do this job for every release, it's a repetitive and tedious thing.

Then assume that the same n JS is referenced on different pages, if we just follow the separate JS to compress, it is not ...

In fact, we would like to have such a tool to help us to compress JS, and this tool only needs us to click on it, and then it will follow the rules we set to automatically compress JS, and then we can easily put these compressed JS posted to the site.

The so-called knife-sharpening mistake wood workers, let's take a look at the implementation principle of this tool! (Specific rules you have to do according to the needs of your project OH)

. NET compression js and CSS-related DLLs

Baidu keyword "Yahoo.Yui.Compressor" Download the relevant DLL, of course, you can also download my upload

Yahoo.Yui.Compressor

The concrete implementation principle (simple example is as follows)
            varJS =Newjavascriptcompressor (); Js.compressiontype= Compressiontype.standard;//Compression TypeJs. Encoding = Encoding.UTF8;//CodingJs. Ignoreeval =false;//uppercase and lowercase conversionsJs. Threadculture =System.Globalization.CultureInfo.CurrentCulture; stringFile =@"F:\angelaTestProject\AngelaDemo20150509\AngelaDemo20150509\javascrptDemo\ajax.js";//This is the file you need to compress.FileInfo Finfo =NewFileInfo (file); stringStrcontent =File.readalltext (File, Encoding.UTF8); Strcontent=js.compress (strcontent); stringNewflie =@"F:\angelaTestProject\AngelaDemo20150509\AngelaDemo20150509\javascrptDemo\ajax.min.js";//This is already existing JS file (save your compressed JS)file.setattributes (Newflie, fileattributes.normal); File.writealltext (Newflie, strcontent, Encoding.UTF8);

Talk about something.

The above just said that the reference to the Yahoo-related compression DLL, can be used to compress JS and compression CSS, then back to our original topic, how to do a tool to achieve the compression of multiple files into a file, in fact, this is too simple, some things as long as we know the principle, The other is just a different way, for example, we can do a C # Windows Forms program, let the user input the original JS file in the path (can be selected or multiple), and then enter the compressed JS file in the same path.

Of course, this method is not flexible enough, we can also use XML files to configure our rules, and then our tools according to the rules we configured to compress.

Finally, our page refers to the only compressed JS address.

Maybe my literary talent is not good enough, also said is relatively simple. In fact the principle is so simple, just use the people choose the road is not the same, out of the same scenery.

Appendix JS Compression Tool

Http://prettydiff.com/?m=beautify&s=http://prettydiff.com/prettydiff.js

http://yui.github.io/yuicompressor/

http://jscompress.com/

Appendix JS Anti-Compression tool

http://jsbeautifier.org/

http://javascriptbeautifier.com/

If you feel this blog post to you have a harvest, think the little woman is still hard, please click on the bottom right corner of the [recommended], Thank you!

. NET using Yui-related DLL compression JS (according to their own rules, think all feel strong and interesting)

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.