Copied to clipboard

Flag this post as spam?

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


  • JJ 41 posts 83 karma points
    Mar 11, 2014 @ 19:05
    JJ
    1

    Bundles

    Hi

    Using System.Web.Optimization, can anyone tell me how to tell Umbraco 7 to let me add my own bundles please?

    Previously i would edited global, but that's compiled now, and used a BundleConfig.cs file in App_Start.

    Thanks 

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Mar 12, 2014 @ 10:29
    David Brendel
    1

    Thats the way it's done in a v6 setup we're using.

    Haven't tryed it in v7 but should also work like this. Make a class that inherits from IApplicationEventHandler and then add this code:

    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            RegisterStyles(BundleTable.Bundles);
            RegisterJavascript(BundleTable.Bundles);
        }
    
        private static void RegisterStyles(BundleCollection bundles)
        {
            //Add all style files. These will be bundled and minified.
            //After everything has been bundled (which only happens when debug=false in the web.config) check if there are no errors in the bundled file. Not all files can be bundled.
            bundles.Add(new StyleBundle("~/bundle/styles.css").Include(
                    "~/css/main.css"
                )
            );
        }
    
        private static void RegisterJavascript(BundleCollection bundles)
        {
            //Add all javascript files. These will be bundled and minified.
            //After everything has been bundled (which only happens when debug=false in the web.config) check if there are no errors in the bundled file. Not all files can be bundled.
            bundles.Add(new ScriptBundle("~/bundle/javascript.js").Include(
                    "~/umbraco/plugins/TrackMedia/Tracking.js",
                    "~/scripts/jquery.validate.js",
                    "~/scripts/slimmage.js",
                    "~/scripts/functions.js"
                )
            );
        }
    
  • Comment author was deleted

    Mar 12, 2014 @ 10:39
  • JJ 41 posts 83 karma points
    Mar 12, 2014 @ 13:21
    JJ
    0

    ah, that seems simpler!

     

    thanks

  • Andreas Johansson 9 posts 42 karma points
    Apr 23, 2015 @ 21:49
    Andreas Johansson
    2

    For thoose who looks here and goes with David Brendels code, Here's an addition the that post.

    When adding bundles, don't add extensions, like .js or .css, it should be like "~/bundles/script" for instance. See http://www.asp.net/mvc/overview/performance/bundling-and-minification for reference.

    Also you'll have to add the bundle path to the reserved paths. Like this ->

    <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/bundles/"/>

    Otherwise the umbraco route-engine will try to map the path to a page (since we don't want ant extension in the bundle)

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Apr 29, 2015 @ 18:12
    Alex Skrypnyk
    0

    Another solution is to use Cruncher - https://github.com/JimBobSquarePants/Cruncher

    Thanks

  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Nov 09, 2016 @ 16:14
    Matt Barlow | jacker.io
    0

    If you are using Cruncher on an Azure web app be sure to set the platform in application settings to 64 bit or it YSODS. :S

Please Sign in or register to post replies

Write your reply to:

Draft