盒式捆绑包与 MVC4 捆绑包

发布于 2025-01-07 17:33:25 字数 1322 浏览 5 评论 0原文

我目前正在开发一个原型 ASP.NET MVC 3 解决方案,该解决方案将用作多个项目重写的基础(来自 Web 表单)。

我的目标之一是跨应用程序实现一些脚本管理,而不是我们目前没有的目标。

MVC 3 有一个缺陷恕我直言:如果您需要在部分视图或模板视图上指定特定脚本 - 您最终可能会失去对脚本块在呈现的 HTML 中的位置的控制,或者必须指定每个脚本块父视图上的依赖 javascript 文件。

我一直在认真考虑使用 http://getcassette.net/ 作为解决所描述问题的框架。然而,MVC4 beta 的最后一个版本让我再次怀疑自己:MVC 的 Bundle 看起来与 Cassette 的 Bundle 非常相似,我再次感到困惑:

  1. 我应该现在实现盒式磁带而不是迁移到 MVC4 捆绑包吗?

  2. 我是否应该自己实现一些简化的脚本管理器(例如 MVC4 预览中的脚本帮助器类),然后迁移到 MVC4

  3. 或者我应该将盒式磁带集成到项目中,并希望它比 MVC 的实现更具面向未来的能力(我现在真的不喜欢这个选项,因为 )

我对卡带本身没有经验,发现自己很难进行比较,并且希望得到任何答案或提示。

编辑: 我只是想到还有另一种选择:安装用于 MVC 捆绑的 beta nuget 包:https://nuget。 org/packages/Microsoft.Web.Optimization

结论: 我对 MVC4 捆绑包实现了解得越多,我注意到的差异就越大:MVC4 捆绑包没有解决上述 MVC3 问题 - 它们只是进行捆绑和集成。缩小化。此外,盒式磁带不仅能够在特定位置呈现脚本标签,还能够以正确的顺序对它们进行排序,这并不简单。 因此,目前我对任何一个解决方案都不满意,我将尝试提出自己的简约实现,希望将来情况会有所改善。

但是,如果您不害怕将 5+ 依赖项和一堆 web.config 更改添加到您的项目中 - 那就使用盒式磁带。我希望它能在某个时候进行更新,以利用内部的 MVC 捆绑来减少功能重复,并希望变得更加模块化。


更新: 从 Cassette 2.0 版本开始,如果您只需要包和 js 依赖解析,则不再需要包含咖啡脚本和 Cassette 的其他功能。所以在这一点上,卡带对我来说显然是赢家。

I am currently working on a prototype ASP.NET MVC 3 solution that will be used as a base for several project rewrites (from web forms).

One of the goals that I have is to implement some script management across application as opposed to none that we currently have.

MVC 3 has a flaw IMHO: if you need specific script specified on a partial view or template view - you might end up either losing control over where script block is located in rendered HTML or having to specify every single dependent javascript file on the parent View.

I have been seriously considering using http://getcassette.net/ as a framework to resolve described issue. However, last release of MVC4 beta made me doubt myself again: MVC's Bundles look really similar to Cassette's Bundles and I am confused again:

  1. Should I implement cassette now and than migrate to MVC4 bundles?

  2. Should I implement some simplified script manager myself (sth. like Scripts helper class in MVC4 preview) and then migrate to MVC4

  3. Or should I integrate cassette into project and hope that it will be more future-proof than MVC's imlementation (I really don't like this option right now just because of sheer number of dependencies cassette comes with).

I have no experience with Cassette itself and find it really hard to make the comparison myself and would appreciate any answers or hints.

EDIT:
I just figured that there is another option: installing beta nuget package for MVC bundling: https://nuget.org/packages/Microsoft.Web.Optimization

CONCLUSION:
The more I look into MVC4 bundle implementation the bigger difference I notice: MVC4 bundles do not address MVC3 issue described above - they just do bundling & minification. Moreover, cassette is not just capable of rendering script tags in a specific place it is also capable of ordering them in correct order which is not trivial.
So at the moment I am not satisfied with either of solutions and I will try to come up with my own minimalistic implementation hoping that situation will improve in the future.

But if you are not afraid of adding 5+ dependencies and bunch of web.config changes into your project - go for cassette. I hope it will be updated at some point to utilize MVC bundling inside to reduce functionality duplication, and hopefully, will become more modular.


UPDATE:
As of version 2.0 of Cassette it is no longer necessary to include coffee script and other features of Cassette if you just need bundles and js dependency resolution. So at this point Cassette is a clear winner to me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

诗笺 2025-01-14 17:33:26

有关 ASP.NET MVC 捆绑的信息位于:http:// weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx

ASP.NET 正在添加一项功能,可以轻松“捆绑”或
将多个 CSS 和 JavaScript 文件“组合”成更少的 HTTP 请求。
这会导致浏览器请求更少的文件,进而
减少获取它们所需的时间。

ASP.NET 的下一个版本还添加了一项新功能,使其
也可以轻松减少或“缩小”内容的下载大小。

看起来它本质上和卡带是一样的。在所有其他条件相同的情况下,请使用 ASP.NET MVC 原生的解决方案。

Information about ASP.NET MVC bundling is here: http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx.

ASP.NET is adding a feature that makes it easy to “bundle” or
“combine” multiple CSS and JavaScript files into fewer HTTP requests.
This causes the browser to request a lot fewer files and in turn
reduces the time it takes to fetch them.

The next release of ASP.NET is also adding a new feature that makes it
easy to reduce or “minify” the download size of the content as well.

Looks like it's essentially the same thing as Cassette. All other things being equal, use the solution that is native to ASP.NET MVC.

℉絮湮 2025-01-14 17:33:26

我最终在我的上一个项目中使用了 Cassette,它运行得很好。如果您使用 NuGet,实际上并没有太多配置,所以我的想法是,现在使用 Cassette,然后如果您愿意的话可以稍后切换,这不会太难。

另一件需要考虑的事情是 Cassette 的编译较少。我不确定 MVC4 捆绑是否可以做到这一点,因为我还没有时间阅读它。

I ended up using Cassette on my last project and it's working pretty well. There's really not a whole lot of configuration to it if you use NuGet, so my thinking is that it wouldn't be too hard to use Cassette now and then switch later if you wanted to.

One other thing to consider is that Cassette does Less compiling. I'm not sure if the MVC4 bundling does that or not since I haven't had time to read up on it.

亽野灬性zι浪 2025-01-14 17:33:26

Cassette 仍然是一个有趣的选择,因为它原生支持 less 和 coffescript。如果您对客户端 mvc 框架(backbone、knockout 等)感兴趣,它还支持 HTML 模板

Cassette is still an interesting alternative as it has native support for less and coffescript. It has also support for HTML Templates, if you are interested in client side mvc frameworks (backbone, knockout etc)

空心空情空意 2025-01-14 17:33:26

正如对此的更新一样,在 Visual Studio 2012 的 Update 2 包中添加了 LESS 和 CoffeeScript 支持,因此它开始看起来越来越像将您需要的转换添加到 Bundling/ 的本机实现中会更好。从长远来看,缩小支持 MVC4,而不是与 Cassette 一起使用。

Just as an update to this, LESS and CoffeeScript support was added in the Update 2 package for Visual Studio 2012, so it's starting to look more and more like it would be better to add what transformations you need to the native implementation of the Bundling/Minification backed into MVC4 than go with Cassette in the long term.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文