Minifying MvcRazorHost for minification of Razor views at compile time.
The library provides a replacement MvcRazorHost that will minify Razor views using one of two methods. The most commonly used method is by replacing the Chunk Visitor (ChunkVisitorMinifyingMvcRazorHost
) and will minify Razor views as the engine processes chunks of markup and Razor code. Another method for comparison is a pre-minifying minifier that seeks to minfy view markup prior to the Razor engine compiling the view (PreMinifyingMvcRazorHost
).
To setup the Chunk Visior version, replace the IMvcRazorHost
in Program.cs
...
services.AddSingleton<Microsoft.AspNetCore.Mvc.Razor.IMvcRazorHost, GuardRex.MinifyingMvcRazorHost.ChunkVisitorMinifyingMvcRazorHost>();
To setup the Pre-Minifing version, replace the IMvcRazorHost
in Program.cs
...
services.AddSingleton<Microsoft.AspNetCore.Mvc.Razor.IMvcRazorHost, GuardRex.MinifyingMvcRazorHost.PreMinifyingMvcRazorHost>();
This is not a "perfect" minifier. You may find in a few spots that a non-breaking space ( 
) is required in markup to preserve a space taken out by the library. This is a temporary library to tide one over until minification becomes first-class in MVC Razor. See: aspnet/Razor#444
Thanks to Thom Kiesewetter @Anderman https://github.com/Anderman for the initial host replacement code.
Version | Changes Made |
---|---|
1.0.0 | Initial Release |