Compressing html and html code

Source: Internet
Author: User

Compressing html and html code

With the optimization of recent research programs, compressing html can reduce the size of html and improve the page speed. Add the following code to the basepage of webform:

1 /// <summary> 2 // rewrite the Render method, to compress the output content 3 /// </summary> 4 /// <param name = "writer"> </param> 5 protected override void Render (HtmlTextWriter writer) 6 {7 StringWriter html = new StringWriter (); 8 HtmlTextWriter tw = new HtmlTextWriter (html); 9 base. render (tw); 10 11 string outhtml = html. toString (); 12 13 outhtml = Regex. replace (outhtml, @ "\ s +", "", RegexOptions. compiled | RegexOptions. multiline); 14 outhtml = Regex. replace (outhtml, "\ r \ n", string. empty, RegexOptions. compiled | RegexOptions. multiline); 15 outhtml = Regex. replace (outhtml ,@"(? <=>) (\ S | \ n | \ t) + (? = <) ", String. Empty, RegexOptions. Compiled | RegexOptions. Multiline); 16 outhtml = Regex. Replace (outhtml," <! --*.*? --> ", String. Empty, RegexOptions. Compiled | RegexOptions. Multiline); 17 18 19 // output to client 20 writer. Write (outhtml); 21}

You need to debug the following items in the project to avoid filtering the output content.

Related Article

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.