捆绑和最小化未呈现正确的路径



我对ASP.NET MVC 4的捆绑和缩小功能有问题。基本上,我有以下捆绑设置:

        bundles.Add(new StyleBundle("~/backendcss").Include(
                    "~/backendContent/bootstrap/css/bootstrap.min.css",
                    "~/backendContent/assets/jui/css/jquery-ui.css",
                    "~/backendContent/assets/jui/jquery-ui.custom.css",
                    "~/backendContent/plugins/uniform/css/uniform.default.css",
                    "~/backendContent/plugins/fullcalendar/fullcalendar.css",
                    "~/backendContent/plugins/fullcalendar/fullcalendar.print.css",
                    "~/backendContent/assets/css/fonts/icomoon/style.css",
                    "~/backendContent/assets/css/main-style.css",
                    "~/backendContent/plugins/pnotify/jquery.pnotify.css",
                    "~/backendContent/plugins/msgbox/jquery.msgbox.css",
                    "~/backendContent/IntroJS/css/introjs.css"));

当它们被放在页面上时,它们显示为:

<link href="/backendContent/assets/jui/css/jquery-ui.css" rel="stylesheet"/>
<link href="/backendContent/assets/jui/jquery-ui.custom.css" rel="stylesheet"/>
<link href="/backendContent/plugins/uniform/css/uniform.default.css" rel="stylesheet"/>
<link href="/backendContent/plugins/fullcalendar/fullcalendar.css" rel="stylesheet"/>
<link href="/backendContent/plugins/fullcalendar/fullcalendar.print.css" rel="stylesheet"/>
<link href="/backendContent/assets/css/fonts/icomoon/style.css" rel="stylesheet"/>
<link href="/backendContent/assets/css/main-style.css" rel="stylesheet"/>
<link href="/backendContent/plugins/pnotify/jquery.pnotify.css" rel="stylesheet"/>
<link href="/backendContent/plugins/msgbox/jquery.msgbox.css" rel="stylesheet"/>
<link href="/backendContent/IntroJS/css/introjs.css" rel="stylesheet"/>
  1. 第一个问题是Tilda ~没有出现在链接的开头,我认为这是问题之一(网站渲染不正确),现在上面所有的css样式表都在解决,但有很多导入和相对url(图像),我认为这些都搞砸了(没有捆绑包,如果我只指向~/backendContent/....,一切都很好

  2. 第二个问题是,当我设置BundleTable.EnableOptimizations = true;时,会有更多的问题,深入挖掘会得到一个巨大的列表(4368,1):运行时错误CSS1019:意外的令牌,找到"@import"(4368,9):运行时错误CSS1019:意外的令牌,找到"url("layout.css")"

我不知道这是否重要,但@Styles.Render("~/backendcss")产生的缩小和渲染风格的链接是:

 <link href="/backendcss?v=eMX6YcVB78xPWZV9Dw6seHqsT742J8_M1irfUC0IdaQ1" rel="stylesheet"/>

有什么想法吗?很抱歉,这是我第一次使用这个功能,因为这个网站有这么多css和js,所以可以节省很多带宽,加快整个网站的速度。再加上它非常酷(如果我能让它工作的话)!!!

  1. ~不应该被渲染。这是asp.net中的一个特殊字符,意思是the root of the application

  2. 我不知道你为什么会对实际的缩小有问题,但如果没有来源,这很难诊断。

  3. 优化后的链接应该是这样的。这个最后的v=xxx用于缓存破坏,这样当您更改css文件时,人们就可以获得更新的css。

我认为要实现缩小,需要添加global.asax文件

BundleTable.EnableOptimizations=true;

您还可以尝试创建不同的组,例如将jqueryui与引导程序分离等等

Darren Kopp是对的"~不应该被渲染。这是asp.net中的一个特殊字符,意味着应用程序的根"。。

不要使用".min",因为当你设置BundleTable.EnableOptimizations = true;时,它会最小化你的文件。。所以应该是这样的;

bundles.Add(new StyleBundle("~/backendcss").Include(
                    "~/backendContent/bootstrap/css/bootstrap.css",
                    "~/backendContent/assets/jui/css/jquery-ui.css",
                    "~/backendContent/assets/jui/jquery-ui.custom.css",
                    "~/backendContent/plugins/uniform/css/uniform.default.css",
                    "~/backendContent/plugins/fullcalendar/fullcalendar.css",
                    "~/backendContent/plugins/fullcalendar/fullcalendar.print.css",
                    "~/backendContent/assets/css/fonts/icomoon/style.css",
                    "~/backendContent/assets/css/main-style.css",
                    "~/backendContent/plugins/pnotify/jquery.pnotify.css",
                    "~/backendContent/plugins/msgbox/jquery.msgbox.css",
                    "~/backendContent/IntroJS/css/introjs.css"));

最新更新