Posts

Showing posts from March, 2019

Enable CORS with a dynamic list of origins

Minification of HTML in ASP.NET

Minification refers to the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser – e.g. code comments and formatting, removing unused code, using shorter variable and function names, and so on.. In today’s post, we are gonna quickly learn how to minify HTML for Asp.Net. We will Minify the HTML produced by  ASP.NET  by using an HttpModule  to remove all white spaces from the Response Stream. First lets create the  Filter  for removing the white spaces using System; using System.IO; using System.Text; using System.Text.RegularExpressions; namespace HtmlMinification { internal class WhitespaceFilter : Stream { private static readonly Regex Pattern = new Regex(@"^\s+", RegexOptions.Multiline | RegexOptions.Compiled); private readonly Stream _stream; public override bool CanRead { get { return true; } } public override bool CanSeek {