Copied to clipboard

Flag this post as spam?

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


  • wschwarte 44 posts 73 karma points
    Dec 04, 2014 @ 21:36
    wschwarte
    0

    Minify HTML/CSS/JS , Gzip compression

    Hi,

    after running gtmetrix on a umbraco 7 site i get a lot of reds in these sections. How can I enable these things in an Umbraco site?

    thanks.

     

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 04, 2014 @ 21:55
    Jeavon Leopold
    2

    Hi, you can find how to enable gzip in this blog post For JS/CSS minification take a look at the Optimus package.

    HTML minification is a bit more tricky, it can be done using the WebMarkupMin NuGet package but this requires you implement route hijacking on your views.

    Hope that's helpful.

    Jeavon

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 05, 2014 @ 06:00
    Jan Skovgaard
    3

    Hi wschwarte

    You can also consider using grunt or gulp to minify your css/javascript as a part of your development process. You can also add a task that will optimize any of your system images (not to be confused with those being uploaded into Umbraco).

    Another option could also be to use the ClientDependency framework, which is baked in Umbraco and created by Shannon who work in Umbraco HQ - You can read more about how to use it here https://github.com/Shazwazza/ClientDependency/wiki

    Hope this helps.

    /Jan

  • Biagio Paruolo 1593 posts 1824 karma points c-trib
    Jul 02, 2016 @ 18:21
    Biagio Paruolo
    0

    Is this already in Umbraco 7?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jan 19, 2015 @ 18:27
    Alex Skrypnyk
    0

    Hi,

    Can somebody share what packages are the best for Umbraco performance best practices ?

    Thanks Alexander

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 19, 2015 @ 18:39
    Jan Skovgaard
    0

    Hi Alex

    As far as I know the "Optimus" package that Jeavon mentions above is the only performance package that exists for Umbraco as such.

    I'm not sure there is a best practice as such since it's very individual how developers and companies want to deal with optimizing performance so I think it's a matter of figuring out your own approach and what feels right in your development setup.

    Just my 2 cents.

    /Jan

  • André Nøbbe Christiansen 10 posts 71 karma points
    Jul 14, 2016 @ 15:09
    André Nøbbe Christiansen
    0

    Has anyone got the WebMarkupMin to work? I haven't... So far this is what i have been doing, but not sure of it's good or bad coding, but it does the job.

    I have made some changes:


    WhitespaceFilter.cs

    // Before
    private static readonly Regex Pattern = new Regex(@"^\s+", RegexOptions.Multiline | RegexOptions.Compiled);
    
    // After
    private static readonly Regex Pattern = new Regex(@"/\*(.*?)\*/|<!--(?!\[).*?(?!<\])-->|^\s+|\s+$|\s\s+|[\r\n\t\f]+", RegexOptions.Multiline | RegexOptions.Compiled);
    

    HttpModule.cs

    // Changed

    // Before
    private void ContextBeginRequest (object sender, EventArgs e) {
        HttpApplication app = sender as HttpApplication;
    
        if(IsSupportedContentType(app)) {
            app.Response.Filter = new WhitespaceFilter(app.Response.Filter);
        }
    }
    
    // After
    private void ContextBeginRequest (object sender, EventArgs e) {
        HttpApplication app = sender as HttpApplication;
    
        if(IsSupportedContentType(app)) {
            app.Response.Filter = new WhitespaceFilter(app.Response.Filter);
        }
    }
    

    // Added

    /// <summary>
    /// Returns true if filter is not null and content type is html.
    /// </summary>
    private Boolean IsSupportedContentType (HttpApplication filterContext) {
    return filterContext != null
        && !filterContext.Request.RawUrl.Contains(".axd")
        && !filterContext.Request.RawUrl.Contains(".ashx")
        && !filterContext.Request.RawUrl.Contains(".png")
        && !filterContext.Request.RawUrl.Contains(".jpeg")
        && !filterContext.Request.RawUrl.Contains(".jpg")
        && !filterContext.Request.RawUrl.Contains(".gif")
        && !filterContext.Request.RawUrl.Contains(".mp4")
        && !filterContext.Request.RawUrl.Contains(".webm")
        && !filterContext.Request.RawUrl.Contains(".css")
        && !filterContext.Request.RawUrl.Contains(".js")
        && filterContext.Context.Response.Filter != null
        && !filterContext.Request.RawUrl.Contains("umbraco")
        && filterContext.Context.Response.ContentType.Equals("text/html", StringComparison.OrdinalIgnoreCase);
    }
    
  • Sean Håkansson 66 posts 192 karma points
    Sep 08, 2016 @ 18:36
    Sean Håkansson
    0

    Interesting! How come your IsSupportedContentType is not checking for .cshtml only? Do you cache the result somehow, or does it run minify on each HTTP request?

    I've been looking in to various projects and methods on my spare time, and found this article and his tool on github: http://www.deanhume.com/Home/BlogPost/a-simple-html-minifier-for-asp-net/2097

    Basicly, any runtime minification will in theory cost performance, but if you do it on build/publish its win-win.

    I've also looked in to MVC outputCache, and there is compress attribute, but that will "only" gzip and I want both.

    Good article about gzip vs min: http://madskristensen.net/post/effects-of-gzipping-vs-minifying-html-files

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Jul 14, 2016 @ 18:36
    Søren Kottal
    0

    Check out this article too, especially part 4 and 5 regarding caching and compression.

    http://24days.in/umbraco/2013/6-easy-configuration-tweaks/

  • Yakov Lebski 549 posts 2113 karma points
    Jul 02, 2017 @ 16:03
    Yakov Lebski
    1

    We just do this package for Html minification - https://our.umbraco.org/projects/developer-tools/html-minifier/ May be will be useful.

  • Mike Chambers 635 posts 1252 karma points c-trib
    Dec 21, 2017 @ 14:58
    Mike Chambers
    0

    Hi Yakov, can't see a way to report issues on you package... or where to find the source code.. so apologies for hijacking this thread.

    The minifier seems to be a little overzealous with <li>...</li> stripping the closing tag?

    <aside id=social-media class=pull-right><p>Follow us on<ul class=list-inline><li><a href=https://www.facebook.com/ aria-label=Facebook> <i class="fa fa-3x fa-facebook-square" aria-hidden=true></i><span class=sr-only>Facebook</span> </a><li><a href=https://twitter.com/ aria-label=Twitter> <i class="fa fa-3x fa-twitter-square" aria-hidden=true></i><span class=sr-only>Twitter</span> </a><li><a href=http://www.youtube.com/user/ aria-label=YouTube> <i class="fa fa-3x fa-youtube-play" aria-hidden=true></i><span class=sr-only>YouTube</span> </a><li><a href=https://www.instagram.com/ aria-label=Instagram> <i class="fa fa-3x fa-instagram" aria-hidden=true></i><span class=sr-only>Instagram</span> </a></ul></aside>
    

    for instance... is that by design?

    Are there any options to set that could avoid this, it seems to cause rendering differnces between uncompressed and compressed. (padding is removed) (perhaps a RemoveOptionalEndTags flag?)

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jul 03, 2017 @ 08:00
    Dan Diplo
    1

    We tend to use Microsoft's ASP.NET MVC optimisation package that can be installed via NuGet - https://www.nuget.org/packages/Microsoft.AspNet.Web.Optimization/

    It can both minify and bundle (combine) JS and CSS files. You can even configure it so it only does this in release mode, which is handy. It's pretty simple to use.

    https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification

    https://www.codeproject.com/Articles/748849/ASP-NET-Web-Optimization-Framework

    Rather than modify Global.asax you can register your bundles using the Application_Started event in Umbraco - see https://our.umbraco.org/documentation/reference/events/Application-Startup

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Jul 03, 2017 @ 08:47
    Paul Seal
    0

    I use bundling for minifying css and js

    http://www.codeshare.co.uk/blog/how-to-use-bundling-to-minify-css-and-javascript-in-mvc-and-umbraco/

    I never minify html. I went down that route once, but the work involved in getting it working and sorting out the cases where you do need whitespace in your html etc far outweighs the benefits of having it in place.

  • Manish 373 posts 932 karma points
    Jul 03, 2017 @ 13:27
    Manish
    0
  • John Bergman 483 posts 1132 karma points
    Aug 01, 2017 @ 18:46
    John Bergman
    2

    I have webmarkupmin working. It wasn't too bad to do compression/minification for the whole site. This is the secret sauce..

    public class lMinifierStartup : IApplicationEventHandler, IApplicationStartupHandler, IDiscoverable
    {
        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            GlobalFilterCollection filters = GlobalFilters.Filters;
            filters.Add(new CompressContentAttribute());
            filters.Add(new MinifyHtmlAttribute());
            filters.Add(new MinifyXmlAttribute());
    
            //-- Configure Web Markup Minimizer
            //Configure(WebMarkupMinConfiguration.Instance);
        }
    
    }
    

    In my case, I added Configuration based on this to eliminate Yellow Screens of death should there be a malformed page (mismatched tags, etc)

    https://github.com/Taritsyn/WebMarkupMin/issues/16

  • MB 113 posts 422 karma points
    Jan 17, 2019 @ 02:27
    MB
    0

    Apologies for the necro-posting, but I'm interested in experimenting with webmarkupmin to minimize html at a site-wide level.

    I'm confused as to which of the many NG packages should be used ?

    I'm guessing WebMarkupMin.AspNet4.Mvc but having trouble with the rather terse wiki guides.

    Last time I messed with html minimizing was by intercepting the render event on WebForms masterpages (i.e. a while back) so using this package is non-obvious to me at the moment.

  • John Bergman 483 posts 1132 karma points
    Jan 17, 2019 @ 06:08
    John Bergman
    0

    Here are the packages I am using currently (plus their dependencies)

    WebMarkupMin.AspNet.Common

    WebMarkupMin.AspNet4.Common

    WebMarkupMin.AspNet4.Mvc

    WebMarkupMin.Core

    WebMarkupMin.MsAjax

    WebMarkupMin.Yui

  • MB 113 posts 422 karma points
    Jan 18, 2019 @ 07:42
    MB
    0

    Cheers, took me a while to work out the packages I needed from that - in my case WebMarkupMin.AspNet4.Mvc and WebMarkupMin.Yui (which both install others as dependencies) - and then working out the configuration process in the ApplicationStarting event. I found that only the default css minifier is able to deal with css variables, and that the Yui NG-Package is pedantic about the platform version, forcing me to upgrade from 4.5.1 to 4.5.2, but eventually I got it minifying/compressing html, in-line jscript and in-line css-styles, as expected.

  • John Bergman 483 posts 1132 karma points
    Jan 19, 2019 @ 05:44
    John Bergman
    0

    Cool.

    We ran into a lot of issues when trying to minify 3rd party javascript… minifing them simply caused them not to run anymore.

Please Sign in or register to post replies

Write your reply to:

Draft