Web Markup Minifier

repository·master·Indexed 19 days ago

https://github.com/taritsyn/webmarkupmin

A .NET library used to reduce the payload size of HTML, XML, and markup-based web content by minifying whitespace, comments, and embedded CSS/JS. It supports .NET Framework 4.0+, .NET Standard 1.3+, and .NET 9/10, with specialized integration modules for ASP.NET 4.X (MVC, Web Forms, HTTP Modules) and ASP.NET Core (1.X through 10). The library includes built-in minifiers and provides adapters for external engines such as MS Ajax, YUI Compressor, and NUglify, as well as Brotli compression support.

Tokens
2.5K
Snippets
2
Records
24
Agent score
67%

What's inside WebMarkupMin

  1. Overview of Web Markup Minifier

    master

    Web Markup Minifier (WebMarkupMin) is a .NET library designed to improve web application performance by reducing the size of HTML, XHTML, and XML code. It achieves this by removing extra whitespaces, comments, and redundant code.

    Key capabilities include:

    • Markup Minification: HTML, XHTML, and XML.
    • Embedded Content Minification: Automatically minifies CSS within <style> tags and attributes, and JavaScript within <script> tags, event attributes, and javascript: protocol hyperlinks.
    • Template Engine Support: Supports minification for views using KnockoutJS, Kendo UI MVVM, and AngularJS 1.X.

    WebMarkupMin includes built-in, lightweight minifiers for CSS and JavaScript, but can be extended with more powerful engines via additional modules.

  2. What is WebMarkupMin.AspNet.Common?

    master
    WebMarkupMin.AspNet.Common is an auxiliary package designed to support the ASP.NET extensions of the Web Markup Minifier ecosystem. It provides the shared classes and interfaces required by various ASP.NET-specific implementations (such as ASP.NET MVC or ASP.NET Core) to ensure compatibility and shared functionality across the different extension packages.
  3. Use MS Ajax adapters for CSS and JS minification

    master

    The WebMarkupMin.MsAjax package provides two specific minifier adapters that leverage the Microsoft Ajax Minifier engine:

    • MsAjaxCssMinifier: Used for minifying CSS code.
    • MsAjaxJsMinifier: Used for minifying JavaScript (JS) code.

    These adapters allow you to integrate Microsoft's Ajax minification logic into the Web Markup Minifier ecosystem.

  4. Use NUglify adapters for CSS and JS minification

    master

    The WebMarkupMin.NUglify package provides two minifier adapters that leverage the NUglify engine to perform minification within the Web Markup Minifier ecosystem:

    • NUglifyCssMinifier: Used for minifying CSS code.
    • NUglifyJsMinifier: Used for minifying JavaScript code.

    These adapters allow you to integrate NUglify's minification capabilities into your Web Markup Minifier workflow.

  5. Use YUI Compressor adapters for CSS and JS minification

    master

    The WebMarkupMin.Yui package provides two minifier adapters that use the YUI Compressor for .NET to perform minification:

    • YuiCssMinifier: Used for minifying CSS code.
    • YuiJsMinifier: Used for minifying JavaScript code.

    These adapters allow you to integrate YUI Compressor capabilities into the Web Markup Minifier ecosystem.

  6. Use WebMarkupMin ASP.NET 4.X HTTP modules

    master

    The WebMarkupMin.AspNet4.HttpModules package provides four specialized HTTP modules for processing web content in ASP.NET 4.X environments:

    • HtmlMinificationModule: Minifies HTML code.
    • XhtmlMinificationModule: Minifies XHTML code.
    • XmlMinificationModule: Minifies XML code.
    • HttpCompressionModule: Compresses text content using GZIP or Deflate algorithms.

    These modules allow you to automate the minification and compression of markup and text content as it is served by your ASP.NET application.

  7. Use WebMarkupMin.AspNet4.Mvc action filters

    master

    The WebMarkupMin.AspNet4.Mvc package provides several action filters to automate the minification and compression of web responses in ASP.NET 4.X MVC applications. You can apply these filters to specific actions or controllers to handle different markup types and compression methods.

    Available filters:

    • MinifyHtmlAttribute: Minifies HTML code.
    • MinifyXhtmlAttribute: Minifies XHTML code.
    • MinifyXmlAttribute: Minifies XML code.
    • CompressContentAttribute: Compresses text content using GZIP or Deflate algorithms.
  8. Extend WebMarkupMin with advanced JS and CSS minifiers

    master

    While WebMarkupMin.Core includes built-in minifiers (based on JSMin and Efficient stylesheet minifier), you can install additional modules to use more powerful minification algorithms:

    • WebMarkupMin.MsAjax: Provides adapters for the Microsoft Ajax Minifier.
    • WebMarkupMin.Yui: Provides adapters for the YUI Compressor for .NET.
    • WebMarkupMin.NUglify: Provides adapters for NUglify.
  9. Use Brotli compression in WebMarkupMin

    master

    WebMarkupMin.AspNet.Brotli provides the BrotliCompressor adapter to compress text content using the Brotli algorithm.

    Implementation Details:

    • For older environments, BrotliCompressor is based on BrotliSharpLib (version 0.3.3).
    • For .NET Standard 2.1 and .NET 9, it uses the built-in compressor from the System.IO.Compression namespace.

    Important Compatibility Note for ASP.NET Core: If you are using extensions for ASP.NET Core 3.1 or higher, do NOT use the BrotliCompressor class. Instead, use the BuiltInBrotliCompressor class found in the WebMarkupMin.AspNet.Common.Compressors namespace. If you switch to BuiltInBrotliCompressor, you can uninstall the WebMarkupMin.Brotli package.