捆绑 CSS CDN
Bundling CSS CDN
在应用缩小和捆绑之前,我有一个工作站点。原文CSS我没写。问题源于三个 @import url
语句用于引入 Google 字体。
为了解决这个问题,我决定从相关的 CSS 文件中删除 @import url
并将它们单独添加到我的 BundleConfig.cs class .但是,我无法弄清楚实现这一点的语法:
public static void RegisterBundles(BundleCollection bundles)
{
....
bundles.UseCdn = true;
var templateOriginalPath1
= "http://fonts.googleapis.com/css?family=Lobster";
var templateOriginalPath2 =
"http://fonts.googleapis.com/css?family=Oswald:400,700,300";
var templateOriginalPath3
= "http://fonts.googleapis.com/css?family
=Ubuntu:300,400,500,700,300italic,400italic,700italic";
....
bundles.Add(new StyleBundle("~/bundles/templateOriginal1",
templateOriginalPath1));
bundles.Add(new StyleBundle("~/bundles/templateOriginal2",
templateOriginalPath2));
bundles.Add(new StyleBundle("~/bundles/templateOriginal3",
templateOriginalPath3));
}
显然,语法是正确的。有一个 known bug 会导致优化框架在出现包含 @import url
语句的 CSS 样式表时阻塞。
解决方法太麻烦了,不值得。希望这对其他人有用。我第一次看到这个错误 here。
您必须在开发者工具(我使用 Firefox 开发者浏览器)中检查响应 headers 以查看错误的详细信息:
/* Minification failed. Returning unminified contents.
(1409,1): run-time error CSS1019: Unexpected token, found '@import'
(1409,9): run-time error CSS1019: Unexpected token,
found '"http://fonts.googleapis.com/css?family=Lobster"'
(1409,57): run-time error CSS1019: Unexpected token, found ';'
(1410,1): run-time error CSS1019: Unexpected token, found '@import'
在应用缩小和捆绑之前,我有一个工作站点。原文CSS我没写。问题源于三个 @import url
语句用于引入 Google 字体。
为了解决这个问题,我决定从相关的 CSS 文件中删除 @import url
并将它们单独添加到我的 BundleConfig.cs class .但是,我无法弄清楚实现这一点的语法:
public static void RegisterBundles(BundleCollection bundles)
{
....
bundles.UseCdn = true;
var templateOriginalPath1
= "http://fonts.googleapis.com/css?family=Lobster";
var templateOriginalPath2 =
"http://fonts.googleapis.com/css?family=Oswald:400,700,300";
var templateOriginalPath3
= "http://fonts.googleapis.com/css?family
=Ubuntu:300,400,500,700,300italic,400italic,700italic";
....
bundles.Add(new StyleBundle("~/bundles/templateOriginal1",
templateOriginalPath1));
bundles.Add(new StyleBundle("~/bundles/templateOriginal2",
templateOriginalPath2));
bundles.Add(new StyleBundle("~/bundles/templateOriginal3",
templateOriginalPath3));
}
显然,语法是正确的。有一个 known bug 会导致优化框架在出现包含 @import url
语句的 CSS 样式表时阻塞。
解决方法太麻烦了,不值得。希望这对其他人有用。我第一次看到这个错误 here。
您必须在开发者工具(我使用 Firefox 开发者浏览器)中检查响应 headers 以查看错误的详细信息:
/* Minification failed. Returning unminified contents.
(1409,1): run-time error CSS1019: Unexpected token, found '@import'
(1409,9): run-time error CSS1019: Unexpected token,
found '"http://fonts.googleapis.com/css?family=Lobster"'
(1409,57): run-time error CSS1019: Unexpected token, found ';'
(1410,1): run-time error CSS1019: Unexpected token, found '@import'