3

我正在使用带有 Bootstrap 的 ASP.NET MVC 4,我注意到我的项目与许多关于“使用 Bootstrap 构建网站”的文章和教程有点不同,他们一直提到使用 Javascript 的缩小文件和 CSS(bootstrap.min.css,bootstrap.min.js),尽管文件在目录中,但我只有没有 min 的文件。

我读过这些文件,但我不明白,也许有人可以澄清它们的使用,如果我需要在我的包配置中添加对它们的引用?

我的代码如下所示:

_Layout.cshtml:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <a href="@Url.Action("Index", "Home")" class="navbar-brand">
                    <span class="glyphicon glyphicon-filter"></span> SelectorIT - OnLine
                </a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>


还有我的BundleConfig.cs:

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(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // 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(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));

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

我有两个问题:

  1. 当我没有参考 bootstrap.min.css, bootstrap.min.js 时,我错过了什么?
  2. 我应该在以下位置添加对这些文件的引用:

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

4

1 回答 1

1

min 文件删除所有不必要的字符以使文件更小。这减少了加载时间。来源

如果您正在构建一个小型个人项目,则性能可能没有很高的优先级。如果您正在为其他人或组织构建站点,我建议使用最低版本。

于 2014-06-08T12:03:27.093 回答