Created
November 11, 2021 15:12
-
-
Save gistlyn/5386935f1752e2da846598ac38380b21 to your computer and use it in GitHub Desktop.
Use Nuglify's Advanced JS/CSS/HTML Minifiers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dotnet add package NUglify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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