0

我已经使用 System.Web.Optimization & WebGrease DLL 使用以下代码在我的项目中自动捆绑和缩小 javascript 和 css 文件。

using System.Web.Optimization;
using WebGrease;

protected void Application_Start()
{
    RegisterBundles(BundleTable.Bundles);
    BundleTable.EnableOptimizations = false;

}
public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/Content/Script/Common/").Include("~/Content/Scripts/PTax/Common/ViewPort.js",
                                                                        "~/Content/Scripts/PTax/Common/jquery.rotate.js",
                                                                        "~/Content/Scripts/PTax/Common/jquery.loupe.js",
                                                                        "~/Content/Scripts/PTax/Common/Accordion.js",
                                                                        "~/Content/Scripts/PTax/Common/Progress.js",
                                                                        "~/Content/Scripts/PTax/Common/AjaxGlobalHandler.js",
                                                                        "~/Content/Scripts/PTax/Common/DialogBox.js",
                                                                        "~/Content/Scripts/PTax/Common/Common.js",
                                                                        "~/Content/Scripts/PTax/Common/DateValidations.js"));

}

在我的项目中,某个模块只有一个 javascript 文件。我不需要将它与任何其他文件捆绑在一起。所以我只需要它缩小它。我怎样才能做到这一点。

4

1 回答 1

0

可以新建一个bundle,(创建多个bundle是正常的)

bundles.Add(new ScriptBundle("~/bundles/get").Include("~/Scripts/app/home.js"));

然后在必要的视图中渲染脚本

@Scripts.Render("~/bundles/home")
于 2014-02-19T08:21:18.583 回答