Skip to content

Minifying MvcRazorHost for minification of Razor views at compile time.

License

Notifications You must be signed in to change notification settings

guardrex/GuardRex.MinifyingMvcRazorHost

Repository files navigation

Minifying MvcRazorHost

Minifying MvcRazorHost for minification of Razor views at compile time.

Operation

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>();

Experimental!

This is not a "perfect" minifier. You may find in a few spots that a non-breaking space (&nbsp) 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

Acknowledgement

Thanks to Thom Kiesewetter @Anderman https://github.com/Anderman for the initial host replacement code.

Version History

Version Changes Made
1.0.0 Initial Release

About

Minifying MvcRazorHost for minification of Razor views at compile time.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages