Following is the code for the page on which you want to remove white spaces from the html. It will decrease your html kb by 30 percentage.
using System.Text;
using System.Text.RegularExpressions;
private static readonly Regex REGEX_BETWEEN_TAGS = new Regex(@">\s+<", RegexOptions.Compiled);
private static readonly Regex REGEX_LINE_BREAKS = new Regex(@"\n\s+", RegexOptions.Compiled);
///
/// Initializes the
/// controls of the
///
/// The
protected override void Render(HtmlTextWriter writer)
{
using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new System.IO.StringWriter()))
{
this.Page.Title = CommonFunctions.HtmlEncode(this.Page.Title);
base.Render(htmlwriter);
string html = htmlwriter.InnerWriter.ToString();
html = REGEX_BETWEEN_TAGS.Replace(html, "> <");
html = REGEX_LINE_BREAKS.Replace(html, string.Empty);
writer.Write(html.Trim());
}
}
One of the efforts for increasing the performance of the asp.net websites.
ReplyDelete