1

我有我的脚本和 CSS 捆绑包

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
            "~/Scripts/jquery-{version}.js"));

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

bundles.Add(new ScriptBundle("~/bundles/initialization").Include(
            "~/Scripts/Custom/Common/CustomEventURLS.js",
            "~/Scripts/Custom/Common/CommonFunctions.js",
            "~/Scripts/Custom/Common/GlobalVariables.js"
            ));

bundles.Add(new ScriptBundle("~/bundles/custom").Include(
    "~/Scripts/Custom/kendoNotification.js",
    "~/Scripts/Custom/Common/CommonControlsJS.js",
    "~/Scripts/Custom/Reporting/Reporting.js",
    "~/Scripts/Custom/Common/Base64ToBinary.js",
    "~/Scripts/Custom/Plugins/Custom_Plugins.js",
    "~/Scripts/2c_Combined_JS.js",
    "~/Scripts/2c_Administration_JS.js",
    "~/Scripts/Custom/Administration/FirstTimeLogin.js"
    ));

bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
            "~/Scripts/modernizr-*"));

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

//BundleTable.EnableOptimizations = true;

如果我有 BundleTable.EnableOptimizations = true; 注释掉然后一切正常加载,但是一旦我取消注释,我就会开始收到关于它找不到某些功能的错误。所以这让我相信,当我启用优化时,它会使我的所有脚本都乱序。

在我的布局页面的标题中

@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/initialization")

就在身体支架关闭之前

@Scripts.Render("~/bundles/custom")

自定义位于底部的原因是因为我需要在这些脚本触发之前加载 dom。

如果我不使用捆绑和缩小,那么每次发布应用程序时,我都必须始终执行 ctrl+f5,这并不好。

我该如何解决这个问题,以便我的脚本不会被重新排序?

4

2 回答 2

1

查看并查看由我最喜欢的 Web 开发人员之一Matthew Jones编写的Bundling and Minification - ASP.NET MVC Demystified 。

于 2019-06-12T15:11:22.873 回答
1

RegisterBundles函数中添加以下内容作为第一行:

bundles.IgnoreList.Clear();

还要确保所有最小文件都是有效文件(css 和 js)。

于 2019-06-12T14:45:13.117 回答