This is my first MVC app. I'm looking for best practice feedback on how to best bundle the files that I need, the order to bundle them, the placement of the @render methods within the containing html page.


namespace StateAssessment
    using System.Web.Optimization;

    public class BundleConfig
        // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(

            bundles.Add(new ScriptBundle("~/bundles/jquery-ui").Include(

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(

            bundles.Add(new StyleBundle("~/Content/css").Include(

            // Set EnableOptimizations to false for debugging. For more information,
            // visit http://go.microsoft.com/fwlink/?LinkId=301862
            #if DEBUG
                BundleTable.EnableOptimizations = false;
                BundleTable.EnableOptimizations = true;


<!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>State Assessment Recovery System - @ViewBag.Title</title>    
    <link href="~/Content/themes/base/all.css" rel="stylesheet" />
    @RenderSection("Styles", required: false)

    @using StateAssessment.CommonHelpers.HelperControls;

    <meta name="description" content="The description of my page" />

    @RenderSection("scripts", required: false)


@model StateAssessment.ViewModels.StateAssessment.Index

@section Styles {
    <link href="@Url.Content("~/Content/ViewSpecific/StateAssessment/IndexItem.css")"  rel="stylesheet"/>

    <!--markup goes here -->

    @section Scripts {

         <script src="~/Scripts/ViewSpecific/StateAssessment/Index.js" type="text/javascript">

The best practice moved from using dotNet code for bundling, to use tools for this.

The most popular and best practised tools are:

  • gulp
  • grunt

Both are tools that work on top of nodejs, an easy to install app.

Use either of these tools to minify and bundle your js and css and reference to result file.

You can make the tooling run on build events of your project to always have it bundled

But, best practise here is to use development files in development (to keep yourdev cycle a short as possible). And in production use the bundled and minified version.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.