2

当我将 jquery ui 添加到包中时,我最终得到:

bundles.Add(new StyleBundle("~/Content/css").Include(
                            "~/Content/themes/base/jquery.ui.core.css",
                            "~/Content/themes/base/jquery.ui.resizable.css",
                            "~/Content/themes/base/jquery.ui.selectable.css",
                            "~/Content/themes/base/jquery.ui.accordion.css",
                            "~/Content/themes/base/jquery.ui.autocomplete.css",
                            "~/Content/themes/base/jquery.ui.button.css",
                            "~/Content/themes/base/jquery.ui.dialog.css",
                            "~/Content/themes/base/jquery.ui.slider.css",
                            "~/Content/themes/base/jquery.ui.tabs.css",
                            "~/Content/themes/base/jquery.ui.datepicker.css",
                            "~/Content/themes/base/jquery.ui.progressbar.css",
                            "~/Content/themes/base/jquery.ui.theme.css"

Internet Explorer限制加载 31 个样式表,其中 jquery 占用了 12 个。添加 yui reset、base 和 fonts 我已经有 15 个样式表,没有加载任何网站样式或插件样式表。

显然,捆绑后一切正常,因为只生成了一个样式表。我的第一直觉是使用那些使用 @Import 的那些,但这会导致捆绑失败或不缩小。

除了更少的样式表之外,最好的解决方法是什么? 我目前的解决方案是一种#if DEBUG构造,但有更好的方法吗?

#if DEBUG
     bundles.Add(new StyleBundle("~/Content/css").Include(
                        "~/Content/themes/base/jquery.ui.all.css"));
#else
     bundles.Add(new StyleBundle("~/Content/css").Include(
                            "~/Content/themes/base/jquery.ui.core.css",
                            "~/Content/themes/base/jquery.ui.resizable.css",
                            "~/Content/themes/base/jquery.ui.selectable.css",
                            "~/Content/themes/base/jquery.ui.accordion.css",
                            "~/Content/themes/base/jquery.ui.autocomplete.css",
                            "~/Content/themes/base/jquery.ui.button.css",
                            "~/Content/themes/base/jquery.ui.dialog.css",
                            "~/Content/themes/base/jquery.ui.slider.css",
                            "~/Content/themes/base/jquery.ui.tabs.css",
                            "~/Content/themes/base/jquery.ui.datepicker.css",
                            "~/Content/themes/base/jquery.ui.progressbar.css",
                            "~/Content/themes/base/jquery.ui.theme.css"));
#endif
4

1 回答 1

1

如果您真的需要所有主题,只需jquery.ui.all.css在 DEBUG 和 RELEASE 模式中包含。

bundles.Add(new StyleBundle("~/Content/css").Include(
    "~/Content/themes/base/jquery.ui.all.css"));

这样,在 DEBUG 模式下你会得到一个 CSS 文件,而在 RELEASE 模式下你会得到一个带有缓存头的压缩 CSS 文件。

于 2012-10-01T12:59:44.343 回答