什么时候不使用MVC捆绑? [英] When NOT to use MVC Bundling?

查看:120
本文介绍了什么时候不使用MVC捆绑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在最近的项目中遇到了一个奇怪的问题. 我正在使用 Trent Richardson的Timepicker 控件在我的MVC 4应用程序中使用时间选择器功能.我使用MVC捆绑功能捆绑了相关的JQuery文件.我发现此方法在开发环境中运行良好(Visual Studio 2012).

I came across a strange issue in my recent project. I was using Trent Richardson's Timepicker control to avail time picker functionality in my MVC 4 application. I had relevant JQuery file bundled using MVC bundling feature. I found this working quite well in development environment (Visual Studio 2012).

但是,当我在IIS上部署网站时,我开始遇到一个奇怪的问题,在该特定捆绑包中出现了JavaScript错误"功能预期".我可以看到该捆绑包已加载,因为在脚本"标签中选择该捆绑包时,开发人员工具正在显示javascript代码.

But when I deployed the website on IIS, I started facing a strange issue, and there was a javascript error "function expected" in that particular bundle. I could see the bundle got loaded because developer tool was showing javascript code when that bundle was selected in "scripts" tab.

最后,当我直接引用JQuery文件而不是bundle时,它在IIS上开始正常工作.尽管问题得以解决,但我现在很好奇,如果捆绑了该特定文件,出了什么问题,并且如果MVC捆绑实际上是一个问题,那为什么它在开发环境中却能在IIS中很好地工作?

Finally, when I referenced the JQuery file directly instead of bundle, it started working fine on IIS. Though the problem got solved, I am now curious to know what was wrong with that particular file if bundled, and if MVC bundling was actually an issue, then why it was working well in development environment, but not in IIS?

对此表示赞赏的任何灯饰.

Any lights on this much appreciated.

推荐答案

缩小是一个复杂的过程,它使用诸如变量名缩短,空格消除,注释删除等技术来缩小脚本/样式的大小.它使用ASP.依靠WebGrease进行压缩的NET Web优化.当然,可能会有问题,但是我个人从来没有注意到这一点.

Minification is a complex process by making scripts/styles smaller using techniques such variable name shortening, white space elimination, comments removal, etc... It uses ASP.NET Web Optimization that depends on WebGrease for minification. Of course, there can have issues but I personnaly never noticed that.

在某些情况下,您不应该使用捆绑包

Here are some situations, where you should not use bundling

  • 您的捆绑包中只有一个文件.为什么要捆绑?
  • 您仅使用著名的框架,例如JQuery或jQuery UI .不要重新分发别人已经提供的脚本. Google/Microsoft/Amazon/...已经为最受欢迎的开源JavaScript库提供CDN.

  • There is only one file in your bundle. Why bundling ?
  • You are using only famous frameworks such as JQuery or jQuery UI. Do not redistribute scripts that are already served by someone else. Google/Microsoft/Amazon/... already provide CDN for the most popular, open-source JavaScript libraries.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

您的捆绑包仅占用几个字节. Web性能优化建议限制Web请求的数量.一切都有代价.并不是很理想,但是有时最好将内联脚本放入页面中.

Your bundle takes only a few Bytes. Web performance Optimization suggests to limit the number of web requests. Everything has a cost. Not very optimal, but sometimes it's better to put inline scripts in your page.

这篇关于什么时候不使用MVC捆绑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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