Reputation: 7580
I'm trying out ASP.NET Core Web Optimizer which uses NUglify under the hood. It works perfectly for js
and css
and apparently has support for html
as well, but I can't get it to work with razor cshtml. Adding services.AddWebOptimizer(p => p.MinifyHtmlFiles());
doesn't seem to do anything and moving app.UseWebOptimizer();
to after app.UseMvc();
doesn't work either.
Any ideas?
Upvotes: 3
Views: 1486
Reputation: 1
using WebMarkupMin.AspNet.Common.Compressors;
using WebMarkupMin.AspNetCore8;
using WebMarkupMin.Core;
using WebMarkupMin.NUglify;
builder.Services.AddWebMarkupMin(
options =>
{
options.AllowMinificationInDevelopmentEnvironment = true;
options.AllowCompressionInDevelopmentEnvironment = true;
})
.AddHtmlMinification(options =>
{
HtmlMinificationSettings settings = options.MinificationSettings;
settings.RemoveRedundantAttributes = true;
settings.RemoveHttpProtocolFromAttributes = true;
options.CssMinifierFactory = new NUglifyCssMinifierFactory();
options.JsMinifierFactory = new NUglifyJsMinifierFactory();
})
.AddHttpCompression(options =>
{
options.CompressorFactories =
[
new BuiltInBrotliCompressorFactory(new BuiltInBrotliCompressionSettings
{
Level = CompressionLevel.Fastest
}),
new DeflateCompressorFactory(new DeflateCompressionSettings
{
Level = CompressionLevel.Fastest
}),
new GZipCompressorFactory(new GZipCompressionSettings
{
Level = CompressionLevel.Fastest
})
];
});
app.UseWebMarkupMin();
Good Work...
Upvotes: 0
Reputation: 458
using library called WebMarkupMin.AspNetCore5 will help
nuget package link - https://www.nuget.org/packages/WebMarkupMin.AspNetCore5/
ref -https://stackoverflow.com/a/65879818/9641914
Note : mentioned library is for .net 5
Upvotes: 0