c# - 有没有更好的方法来缩小从 aspx 页面生成的 html

标签 c# asp.net

我正在使用以下代码来缩小运行时从 aspx 页面生成的 html。

protected override void Render(HtmlTextWriter writer)
{
    TextWriter output = new StringWriter();
    base.Render(new HtmlTextWriter(output));
    String html = output.ToString();
    html = Regex.Replace(html, @"\n|\t", " ");
    html = Regex.Replace(html, @">\s+<", "><").Trim();
    html = Regex.Replace(html, @"\s{2,}", " ");

    writer.Write(html);
}

是否有更好的方法来做同样的事情。

非常感谢。

最佳答案

是的,通过使用 Html Tidy甚至 HTTP Module .

关于c# - 有没有更好的方法来缩小从 aspx 页面生成的 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3062898/

相关文章:

c# - 使用程序集中的 Web 应用程序版本号 (ASP.NET/C#)

c# - 从没有强类型 IEnumerable 的 WebAPI 返回数据的 json 表示

asp.net - 对字符进行编码

c# - Mailchimp 事件发送错误 - 此事件已发送,无法再次发送

asp.net - 无需重新发布即可从 CodeBehind 跳转到 Anchor

c# - 报告服务 |停止缓存

c# - WPF 命令绑定(bind)到带有 MVVM 的 DataItemTemplate

C# string.Format 在对象参数之前带有 '+'

c# - 删除和退格在 ReSharper 中不起作用

javascript - ASP.NET 检测 Javascript 是否禁用字段