Few weeks ago, Mads Kristens poseted a very usefull post about removing white spaces from your pages. For me, he found the best Regular Expression for this job. He was using the Render method to do it, and it means that if you want to use it in existing site, you need to edit your base page and compile your site again.
I wanted to use it in some sites I have/manage, so I just insert his code into a new ResponseFilter and assign this filter in my Compression component, compile again this dll and replace it in all my sites. Importent thing is, that using this 'remove spaces metho' must folows the rule of that the current request is not made by MS-AJAX component/control, because the ViewState will be corrupted. This check can be easly made by this simple method:
internal static bool IsAjaxPostBackRequest(HttpContext context)
{
return context.Request.Headers["X-MicrosoftAjax"] != null;
}
Also note, that RequestFilters are excuted in order LIFO (the last added filter is the first one to be performed) , so if you use any compression filter (like me), make sure you register the compression filter before this one.
The ResponseFilter code can be download from here:
RemoveWhiteSpaces.cs (2.34 kb)
The compression module with this filter included can be download from this post: Compression component. In this component you can control in wich pages you want to anable or disable the remove spaces option. (exclude specified pages from compression and remove spaces)