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.