Documentation

Page locations

A bundle has an optional PageLocation property. The Bundle.Render methods are overloaded to accept a page location argument. This is useful when some bundles need to be in the <head> of the page, while others are just before </body>.

For example, given this configuration that assigns the PageLocation properties:

public class BundleConfiguration : IConfiguration<BundleCollection>
{
    public void Configure(BundleCollection bundles)
    {
        bundles.Add<ScriptBundle>(
            "scripts/modernizer.js",
            b => b.PageLocation = "head"
        );
        bundles.Add<ScriptBundle>(
            "scripts/jquery.js",
            b => b.PageLocation = "body"
        );
        bundles.Add<ScriptBundle>(
            "scripts/app",
            b => b.PageLocation = "body"
        );
    }
}

Then in a view we can render the scripts for each location.

@{
    Bundles.Reference("scripts/modernizer.js");
    Bundles.Reference("scripts/app");
}
<!DOCTYPE html>
<html>
  <head>
    ...
    @Bundles.RenderScripts("head");
  </head>
  <body>
    ...
    @Bundles.RenderScripts("body");
  </body>
<html>