从MVC生成的HTML中删除多余的空格 [英] Removing extra whitespace from generated HTML in MVC

查看:182
本文介绍了从MVC生成的HTML中删除多余的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当产生值的大的HTML表(> 20MB)。

I have an MVC application view that is generating quite a large HTML table of values (>20MB).

我COM $ P $使用COM pression过滤pssing控制器的看法

I am compressing the view in the controller using a compression filter

 internal class CompressFilter : ActionFilterAttribute
 {
     public override void OnActionExecuting(ActionExecutingContext filterContext)
     {
         HttpRequestBase request = filterContext.HttpContext.Request;
         string acceptEncoding = request.Headers["Accept-Encoding"];
         if (string.IsNullOrEmpty(acceptEncoding))
             return;
         acceptEncoding = acceptEncoding.ToUpperInvariant();
         HttpResponseBase response = filterContext.HttpContext.Response;
         if (acceptEncoding.Contains("GZIP"))
         {
             response.AppendHeader("Content-encoding", "gzip");
             response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
         }
         else if (acceptEncoding.Contains("DEFLATE"))
         {
             response.AppendHeader("Content-encoding", "deflate");
             response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
         }
     }
 }

有没有办法也消除了视图生成之前,我跑了COM preSS过滤多余空白的(相当大)金额(减少COM pression工作量和大小)?

Is there a way to also eliminate the (quite large) amount of redundant whitespace generated in the view before I run the compress filter (to reduce compression workload and size)?

编辑:
我得到它的工作使用由Womp以下建议的WhiteSpaceFilter技术。

I got it working using the WhiteSpaceFilter technique suggested by Womp below.

有关利息这里的结果,由萤火虫所分析的:

For interest here's the results, as analysed by Firebug:

1)没有COM pression,无空白带 - 21MB,2.59分钟

2)用gzip COM pression,无空白带 - 2MB,17.59s

3)用gzip COM pression,空格条 - 558KB,12.77s




所以肯定是值得的。

1) No Compression, no whitespace strip - 21MB, 2.59 minutes
2) With GZIP compression, no whitespace strip - 2MB, 17.59s
3) With GZIP compression, whitespace strip - 558kB, 12.77s

So certainly worth it.

推荐答案

这家伙写道,只需通过一个普通的前pression运行您字节的快速块拷贝带出空间斑点一个整洁的小空白压实。他写了它作为一个HTTP模块,但你可以乘坐7号线主力code脱离了它,它扑通给你的函数。

This guy wrote a neat little whitespace compactor that simply runs a fast block copy of your bytes through a regular expression to strip out blobs of space. He wrote it as an http module, but you could take the 7 lines of workhorse code out of it and plop it into your function.

这篇关于从MVC生成的HTML中删除多余的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆