.net输出重写压缩页面文件的小例子
不知你是否留意过,有一些网站的html代码都是混在一起,没有任何空格和换行等多余字符。它的好处不用多说――界面大小绝对优化。或许您在想,他们这样做大大降低了可读性。的确,我们看是很乱,只能借用第三方软件重新布局代码。但是,我想他们开发时使用的源码不可能是混一团,前不久发现一个页面基类,大概可以解释这个问题,不多说,看源码:
代码如下:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.htmlControls; using System.Text.RegularExpressions; using System.IO; /// <summary> /// PageBase 页面基类 /// </summary> public class PageBase : System.Web.UI.Page { protected override void Render(htmlTextWriter writer) { StringWriter sw = new StringWriter(); HtmlTextWriter htmlWriter = new htmlTextWriter(sw); base.Render(htmlWriter); string html = sw.ToString(); html = Regex.Replace(html, “[f v]“, “”); html = Regex.Replace(html, ” {2,}”, ” “); html = Regex.Replace(html, “>[ ]{1}”, “>”); writer.Write(html); } }
相关推荐
lupeng 2020-11-14
sjcheck 2020-11-10
sjcheck 2020-11-03
meylovezn 2020-08-28
owhile 2020-08-18
Francismingren 2020-08-17
pythonclass 2020-07-29
sunzhihaofuture 2020-07-19
爱读书的旅行者 2020-07-07
行吟阁 2020-07-05
tianqi 2020-07-05
行吟阁 2020-07-04
冰蝶 2020-07-04
lyg0 2020-07-04
owhile 2020-07-04
opspider 2020-06-28
lengyu0 2020-06-28
tianqi 2020-06-21
dadaooxx 2020-06-16