asp.net mvc 5-StyleBundle CdnFallbackExpression有问题吗? [英] asp.net mvc 5 - StyleBundle CdnFallbackExpression questions?

查看:88
本文介绍了asp.net mvc 5-StyleBundle CdnFallbackExpression有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过StyleBundle向我的asp.net mvc 5项目添加了引导CSS文件.

I've added bootstrap CSS files via a StyleBundle to my asp.net mvc 5 project.

(它用作Cdn: https://www.asp.net/ajax/cdn# Bootstrap_Releases_on_the_CDN_14 )

  var bootstrapCssCdnPath = "http://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css";
  var bootstrapCssBundle = new StyleBundle("~/bundles/css/bootstrap", bootstrapCssCdnPath).Include("~/Content/bootstrap.css");
  //bootstrapCssBundle.CdnFallbackExpression // ?
  bundles.Add(bootstrapCssBundle);

  var bootstrapThemeCssCdnPath = "http://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap-theme.min.css";
  var bootstrapThemeCssBundle = new StyleBundle("~/bundles/css/bootstraptheme", bootstrapThemeCssCdnPath).Include("~/Content/bootstrap-theme.css");
  //bootstrapCssBundle.CdnFallbackExpression // ?
  bundles.Add(bootstrapThemeCssBundle);

但是有一个问题:当我添加不正确的URL作为CDN时(例如,添加"ahttp"而不是"http"),我的自定义"fallback" css文件未使用,而是在其中显示了"ahttp://"我的html来源. 当我在Debug或Release上运行网站时,情况相同.

However there is a problem: when I add an incorrect url as CDN (e.g. adding 'ahttp' instead of 'http') my custom "fallback" css file is not used, instead it shows 'ahttp://' in my html source. Same when I'm running my site on Debug or Release.

  1. 为什么不使用我的后备广告?
  2. StyleBundle的CdnFallbackExpression是什么? (尤其是bootstrap.css和bootstrap-theme.css)
  3. .include应该是.min.css文件,还是自动搜索.min.是第一个版本?
  4. 是否有一种方法可以使用带有回退功能的Cdn包含多个CSS文件,这样我就不必每次使用Cdn的CSS文件每次都创建一个新的StyleBundle?

推荐答案

1)这是Microsoft ASP.NET优化框架中的错误,已记录在

1) This is a bug in the Microsoft ASP.NET Optimization Framework, documented here.

2)解决方案是将CdnFallbackExpression修改为一个javascript函数,既可以检查样式表,又可以加载后备,从而可以忽略优化框架中的错误脚本.

2) The solution is to modify the CdnFallbackExpression to be a javascript function that both checks for the stylesheet and loads the fallback, thus ignoring the bad script from the Optimization Framework.

以下是提供解决方法的StyleBundle扩展方法的解决方案:样式包后备广告.

Here is solution which provides a StyleBundle extension method to solve the problem: Style Bundle Fallback.

3)应该有未缩小的版本,例如bootstrap.css(不是bootstrap.min.css).在构建要发布的Web应用程序时,它使用.min版本.更多信息,请参见:不包括.min文件的捆绑包.

3) There should be unminified version like bootstrap.css (not bootstrap.min.css). When you build your web application for release it uses .min version. More here: Bundler not including .min files.

4)不,您不能将多个CSS文件与CDN一起使用(每个文件都必须具有自己的捆绑软件).本文介绍了何时使用CDN(或不使用CDN)以及原因:知道何时进行CDN .

4) No, you can't use multiple CSS files with CDN (each of them must have its own bundle). Here is an article that explains when to use a CDN (or not) and why: Know When To CDN.

这篇关于asp.net mvc 5-StyleBundle CdnFallbackExpression有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆