在Razor视图中使用Bower软件包版本号以获得CDN支持 [英] Use Bower package version numbers in Razor views for CDN support

查看:113
本文介绍了在Razor视图中使用Bower软件包版本号以获得CDN支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2017中使用Bower安装软件包,例如Bootstrap和jQuery。

I am using Bower in Visual Studio 2017 to install packages such as Bootstrap and jQuery.

在我看来,我使用CDN引用相同的库,如下所示:

In my views I am referencing the same libraries using a CDN like so:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css"
          asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.css"
          asp-fallback-test-class="glyphicon"
          asp-fallback-test-property="visibility"
          asp-fallback-test-value="hidden" />

如果我将Bower中的Bootstrap版本从3.3.7更改为其他版本,则必须记得进入Razor视图并将 3.3.7 更改为更新的版本号。

If I change the version of Bootstrap in Bower from 3.3.7 to something else, I then have to remember to go into the Razor view and change 3.3.7 to the updated version number.

我应该使用Gulp来读取bower.json吗?文件并自动使用正确的Boostrap版本号生成Razor视图,或者有一种更简单的方法来确保Bower和我的Razor文件保持同步?

Should I use Gulp to read the bower.json file and automatically generate a Razor view with the correct Boostrap version number or is there an easier way to ensure Bower and my Razor files are kept in sync?

推荐答案

最好与您所有的JavaScript创建一个包。
使用ASP.Net MVC进行捆绑和缩小

Better create a bundle with all your javascript. Bundling and Minification with ASP.Net MVC

当您进行Bower更新时,在运行时捆绑将自动更改JS捆绑包,因此您的客户将获得最新版本。

When you bower update, during runtime, bundling will automatically change the JS bundle so that your client will get the latest version.

这篇关于在Razor视图中使用Bower软件包版本号以获得CDN支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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