by romanovcode · 8y ago · 0 comments
1. Add package called `WebMarkupMin.AspNetCore2`.
2. Add and configure code in your `Startup.cs` like so.
services.AddWebMarkupMin(
options =>
{
options.AllowMinificationInDevelopmentEnvironment = true;
options.AllowCompressionInDevelopmentEnvironment = true;
options.DisablePoweredByHttpHeaders = true;
})
.AddHtmlMinification(
options =>
{
options.MinificationSettings.RemoveRedundantAttributes = true;
options.MinificationSettings.RemoveHttpProtocolFromAttributes = true;
options.MinificationSettings.RemoveHttpsProtocolFromAttributes = true;
// More options if you like so
})
.AddHttpCompression();
Not only will this minfy HTML output, but also apply a lot more optimisations based on your configuration.The main difference between this and WebMarkupMin is that WebMarkupMin runs at runtime - therefore it is costing time to minify when you can already minify the files before launching your web application.
Also, this reduces complexity of the project. Both methods are fine, it's just I prefer this one.