Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jakob Bagterp 11 posts 112 karma points c-trib
    May 26, 2023 @ 12:45
    Jakob Bagterp
    0

    Recommendation for server-side HTML minification in v11?

    There are a few older packages to handle minification of HTML output in runtime (e.g. html-minifier), but they don't work with Umbraco 11. Does anyone have recommendations?

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    May 26, 2023 @ 12:52
    Nik
    100

    Hi Jakob,

    A little while back I was actually doing just this for a v10 site. I ended up using:

    https://github.com/Taritsyn/WebMarkupMin

    Which was really easy to setup and make work. This is what I would use, and I suspect it would work with v11 as well.

    Nik

  • Yakov Lebski 539 posts 2101 karma points
    May 26, 2023 @ 18:57
    Yakov Lebski
    0

    I can make it works for Umbraco 10 and 11 :)

  • Jakob Bagterp 11 posts 112 karma points c-trib
    May 26, 2023 @ 19:15
    Jakob Bagterp
    0

    WebMarkupMin is a great tip, thank you! It works (though it as a little difficult to set it up as the documentation was lacking).

  • Chris Van Oort 110 posts 370 karma points
    Aug 09, 2023 @ 15:10
    Chris Van Oort
    0

    Do you have any information you can share for how to add it?

    Edit: It looks like I can just follow the documentation here? https://github.com/Taritsyn/WebMarkupMin/wiki/ASP.NET-Core-6

    Then for included pages just use new WildcardUrlMatcher("*") to match everything?

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Aug 09, 2023 @ 15:44
    Nik
    1

    Hey Chris,

    I had to do the following else the Umbraco back office broke:

    .AddWebMarkupMin(
                    options =>
                    {                        
                        options.AllowMinificationInDevelopmentEnvironment = true;
                        options.AllowCompressionInDevelopmentEnvironment = true;
                    })
                .AddHtmlMinification(
                    options =>
                    {
                        options.ExcludedPages = new List<IUrlMatcher>{
                            new ExactUrlMatcher("/umbraco"),
                            new WildcardUrlMatcher("/umbraco/*"),
                            new WildcardUrlMatcher("/App_Plugins*")
                        };
                        options.GenerateStatistics = true;
                        options.MinificationSettings.RemoveRedundantAttributes = false;
                        options.MinificationSettings.RemoveHttpProtocolFromAttributes = false;
                        options.MinificationSettings.RemoveHttpsProtocolFromAttributes = false;
                        options.MinificationSettings.MinifyAngularBindingExpressions = false;
                        options.MinificationSettings.MinifyEmbeddedJsCode = false;
                        options.MinificationSettings.MinifyEmbeddedCssCode = false;
                        options.MinificationSettings.MinifyEmbeddedJsonData = false;
                        options.MinificationSettings.MinifyInlineCssCode = false;
                        options.MinificationSettings.MinifyInlineJsCode = false;
                        options.MinificationSettings.EmptyTagRenderMode = WebMarkupMin.Core.HtmlEmptyTagRenderMode.Slash;
                        options.MinificationSettings.RemoveOptionalEndTags = false;
                    });
    

    Thanks

    Nik

  • Chris Van Oort 110 posts 370 karma points
    Aug 10, 2023 @ 17:42
    Chris Van Oort
    0

    Thanks that got us jumpstarted! For anyone, else we configured that in startup.cs.

  • Liam Dilley 148 posts 374 karma points
    Nov 14, 2023 @ 23:35
    Liam Dilley
    0

    Just to expand on this for everyone. In your Startup.CS ensure you have targets for your different environments and then encase this sort of stuff in if conditions so you development/staging environments DO NOT run it so you can debug easier.

  • Jakob Bagterp 11 posts 112 karma points c-trib
    Nov 20, 2023 @ 07:45
    Jakob Bagterp
    0

    True. Good point. 👌

Please Sign in or register to post replies

Write your reply to:

Draft