On ASP.NET MVC 3, I created a Action Filter for white space removal from the entire html. It works as I expected most of the time but now I need to change the RegEx in order not to touch inside pre
element.
I get the RegEx logic from awesome Mads Kristensen's blog and I am not sure how to modify it for this purpose.
Here is the logic:
public override void Write(byte[] buffer, int offset, int count) {
string HTML = Encoding.UTF8.GetString(buffer, offset, count);
Regex reg = new Regex(@"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}");
HTML = reg.Replace(HTML, string.Empty);
buffer = System.Text.Encoding.UTF8.GetBytes(HTML);
this.Base.Write(buffer, 0, buffer.Length);
}
Whole code of the filter:
Any idea?
EDIT:
BIG NOTE:
My intention is totally not speed up the response time. In fact, maybe this slows things down. I GZiped the pages and this minification makes me gain approx 4 - 5 kb per page which is nothing.