加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – CSS / Javascript缩小和捆绑在MVC中究竟是如何工

发布时间:2020-12-16 09:40:12 所属栏目:asp.Net 来源:网络整理
导读:关于MVC如何处理CSS和 Javascript,我有点困惑,我有几个问题. 每当我创建一个默认的MVC(5)应用程序时,我发现已经添加了许多CSS和Javascript库,包括普通和缩小版本. 当我查看BundleConfig类时,我看到常规文件捆绑在一起,但缩小版本不是. 实际使用缩小版本的时
关于MVC如何处理CSS和 Javascript,我有点困惑,我有几个问题.

每当我创建一个默认的MVC(5)应用程序时,我发现已经添加了许多CSS和Javascript库,包括普通和缩小版本.

当我查看BundleConfig类时,我看到常规文件捆绑在一起,但缩小版本不是.

实际使用缩小版本的时间是什么时候?当我调试站点,甚至将其部署到服务器时,我从未看到这些被使用过.这是我必须改变自己的东西,还是有这样的设置?

另外,我是否需要保持这些文件的常规版本和缩小版本同步,或者这是MVC可以自动执行的操作吗?

谢谢

解决方法

捆绑

Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine
or bundle multiple files into a single file. You can create CSS,
JavaScript and other bundles. Fewer files means fewer HTTP requests
and that can improve first page load performance.

缩小

Minification performs a variety of different code optimizations to
scripts or css,such as removing unnecessary white space and comments
and shortening variable names to one character.

你的问题 ?

When I look at the BundleConfig class,I see that the regular files
are bundled together,but the minified versions are not.

答案:

您不需要将缩小版本包含到bundle.B’cos捆绑本身在您的应用程序状态发布时执行此操作(缩小).默认调试模式将使用非缩小版本.

你的问题 ?

When are the minified versions actually used? When I debug the site,
or even deploy it to a server,I never see these being used. Is this
something I have to change myself,or is there a setting for this?

答案:

缩小版将在应用程序处于生产(或发布模式)时使用.
您无需在此处执行任何操作.当您将应用程序的状态更改为发布时,它会自动执行.

你的问题 ?

Also,do I need to keep the regular and minified versions of these
files in sync,or is this something MVC can do automatically?

答案:

你不需要在这里做任何事情.它由框架自动完成.

重要的提示 :

您不需要将缩小的文件添加到bundles.B’cos捆绑文件将在应用程序状态处于发布模式时自动缩小.请阅读以下主题以获取更多信息.

Bundle vs Minification,Which one is the best

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读