Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Created November 11, 2021 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/5386935f1752e2da846598ac38380b21 to your computer and use it in GitHub Desktop.
Save gistlyn/5386935f1752e2da846598ac38380b21 to your computer and use it in GitHub Desktop.
Use Nuglify's Advanced JS/CSS/HTML Minifiers
dotnet add package NUglify
using ServiceStack;
using ServiceStack.Html;
using NUglify;
[assembly: HostingStartup(typeof(MyApp.ConfigureNUglify))]
namespace MyApp
{
public class NUglifyJsMinifier : ICompressor
{
public string Compress(string js) => Uglify.Js(js).Code;
}
public class NUglifyCssMinifier : ICompressor
{
public string Compress(string css) => Uglify.Css(css).Code;
}
public class NUglifyHtmlMinifier : ICompressor
{
public string Compress(string html) => Uglify.Html(html).Code;
}
public class ConfigureNUglify : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(_ => {
Minifiers.JavaScript = new NUglifyJsMinifier();
Minifiers.Css = new NUglifyCssMinifier();
Minifiers.Html = new NUglifyHtmlMinifier();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment