将 PureCSS 添加到 MVC 4.5 包
Add PureCSS to MVC 4.5 bundle
我目前正在学习 ASP.NET 4.5 的 MVC 风格,我决定完全删除 bootstrap 并使用 PureCSS (http://www.purecss.io)。
这主要是因为我的 Web 应用程序几乎不需要脚本,除了代码隐藏和一些用于数据验证等的轻型 JS。
目前我正在链接到来自 Yahoo! 的组合 PureCSS 样式 sheet CDN:
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
在我的 _Layout.cshtml 文件中。这显然是有用的,但是我有两个问题:
- 如果 CVN(无论出于何种原因)fails/goes down/changes,所有样式都消失了,我将不得不即时解决这个问题(或实施一段时间的故障安全切换到另一个CDN)
- 我非常喜欢捆绑的概念,我想捆绑本地 PureCSS 库,以防止上述问题以及 modularization/compartmentalization。
生成这个包是一件简单的事情:
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/purecss_release_1_6/some.css",
"~/Content/purecss_release_1_6/other.css",
"~/Content/purecss_release_1_6/neat.css",
"~/Content/purecss_release_1_6/etc.css",
...
"~/Content/site.css"));
如果是这样,那就很好了,但发行版中有 DOZENS 个 css 个文件。有没有更简洁的方法来捆绑它们?
谢谢!
您可以使用 IncludeDirectory 来引用包含所有 CSS 文件的整个目录。
针对您的案例的示例:
bundles.Add(new StyleBundle("~/Content/css")
.IncludeDirectory("~/Content/purcss_release", "*.css"));
.NET 4.5 中的新功能是一个集成系统,用于从发生故障的 CDN 回退到本地 material。 Tutorial/information: http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx
以上 link 中的可用信息:
The basic idea for CDN fallback is to check for a type or variable
that should be present after a script load, and if it's not there, try
getting that script locally. Note the important escape characters
within the document.write. Here's jQuery:
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='/js/jquery-2.0.0.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
我目前正在学习 ASP.NET 4.5 的 MVC 风格,我决定完全删除 bootstrap 并使用 PureCSS (http://www.purecss.io)。
这主要是因为我的 Web 应用程序几乎不需要脚本,除了代码隐藏和一些用于数据验证等的轻型 JS。
目前我正在链接到来自 Yahoo! 的组合 PureCSS 样式 sheet CDN:
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
在我的 _Layout.cshtml 文件中。这显然是有用的,但是我有两个问题:
- 如果 CVN(无论出于何种原因)fails/goes down/changes,所有样式都消失了,我将不得不即时解决这个问题(或实施一段时间的故障安全切换到另一个CDN)
- 我非常喜欢捆绑的概念,我想捆绑本地 PureCSS 库,以防止上述问题以及 modularization/compartmentalization。
生成这个包是一件简单的事情:
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/purecss_release_1_6/some.css",
"~/Content/purecss_release_1_6/other.css",
"~/Content/purecss_release_1_6/neat.css",
"~/Content/purecss_release_1_6/etc.css",
...
"~/Content/site.css"));
如果是这样,那就很好了,但发行版中有 DOZENS 个 css 个文件。有没有更简洁的方法来捆绑它们?
谢谢!
您可以使用 IncludeDirectory 来引用包含所有 CSS 文件的整个目录。
针对您的案例的示例:
bundles.Add(new StyleBundle("~/Content/css")
.IncludeDirectory("~/Content/purcss_release", "*.css"));
.NET 4.5 中的新功能是一个集成系统,用于从发生故障的 CDN 回退到本地 material。 Tutorial/information: http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx
以上 link 中的可用信息:
The basic idea for CDN fallback is to check for a type or variable that should be present after a script load, and if it's not there, try getting that script locally. Note the important escape characters within the document.write. Here's jQuery:
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='/js/jquery-2.0.0.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>