Taritsyn / WebMarkupMin

The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Apache License 2.0
449 stars 48 forks source link

Support for Blazor WASM? #172

Open fingers10 opened 3 months ago

fingers10 commented 3 months ago

Hi @Taritsyn

Thank you for this wonderful library. I searched the docs and issues and not able to find anything related to Blazor WASM. Does this support Blazor WASM? or can this be combined and used with https://github.com/jsakamoto/BlazorWasmPreRendering.Build which uses build time to prerender blazor wasm projects as HTML and can this be combined with it to Minify the HTML?

Taritsyn commented 3 months ago

Hello, Abdul!

This issue will take some time to research. Most likely, I will have to add an additional property to the CommonHtmlMinificationSettingsBase class to prevent removing comments like these: <!-- %%-PRERENDERING-BEGIN-%% --> and <!-- %%-PRERENDERING-END-%% -->, so that author of the BlazorWasmPreRendering.Build can independently implement this functionality inside his repository.

Taritsyn commented 1 month ago

Hello, Abdul!

In version 2.17.0 a new property was added to HTML and XHTML minification settings - PreservableHtmlCommentList (default is empty). PreservableHtmlCommentList property takes a сomma-separated list of string representations of simple regular expressions, that define what HTML comments can not be removed (e.g. "/^\s*saved from url=\(\d+\)/i, /^\/?\$$/, /^[\[\]]$/").

Simple regular expressions somewhat similar to the ECMAScript regular expression literals. There are two varieties of the simple regular expressions:

  1. /pattern/
  2. /pattern/i

When implementing integration with the BlazorWasmPreRendering.Build library, you need to use the following settings:

var htmlMinifier = new HtmlMinifier(
    new HtmlMinificationSettings()
    {
        PreservableHtmlCommentList = @"/ %%-PRERENDERING(?:-HEADOUTLET)?-(?:BEGIN|END)-%% /"
    }
);