asp.net
Just "accidentally" checked the asp.net generated code, surprised to find that the asp.net output of the code is so not compact, in the label there are countless spaces and tabs (tab), especially with a nested table, the scene is really miserable ah, there are pictures as evidence:
Supposedly adding so many useless spaces in the code generated by ASP.net/tab may be to make the generated HTML code more readable, but the resulting problem is to make the output code larger, in the limited bandwidth today is a crime, waste the user's money, affect the user's experience! And ASP.net is a server-side programming, it is not possible to directly edit the resulting HTML code, even if all the space/tab have gone, will not bring any bad impact!?
Based on the above considerations, the sacrifice of reflector, it was found that HtmlTextWriter in the indent attributes control the size of the indentation, and fortunately this property or public type, really help me also, spent a few minutes, the following code:
1 public class Filterhtmltextwriter:htmltextwriter
2 {
3 Public Filterhtmltextwriter (TextWriter writer, string tabstring)
4:base (writer, tabstring)
5 {
6}
7
8 Public new int Indent
9 {
Ten get {return 0;} Always return 0
One set {base. Indent = 0; //Always set 0
12}
13}
Then overload the page's Render method (better if all pages have a common base class), add a line of code, as follows:
1 public partial class _default:system.web.ui.page
2 {
3 protected override void Render (HtmlTextWriter writer)
4 {
5//Replace writer for our custom class
6 writer = new Filterhtmltextwriter (writer. Innerwriter, "");
7 base. Render (writer);
8}
9//
10}
At this point, let us look at the output of the page again, wow, the annoying space has become less @_@, as shown in the following figure: