ASP.Net MVC Razor Views - 在构建时缩小 HTML

发布于 2024-11-18 20:22:04 字数 394 浏览 3 评论 0原文

首先,虽然我知道 gzip 压缩 HTML 可能会获得与缩小 HTML 一样多(更多?)的性能增益 - 我当然对以下技术是否可行很感兴趣 - 或者是否有人做过类似的事情。

看到其他人在 预编译 MVC Razor 视图,我想知道是否可以以某种方式向这样的过程注入预构建事件,以便可以缩小 HTML,然后再将其构建到单个DLL?

或者还有另一种方法可以在构建时缩小?

我见过几个人想出了通过运行时技术来缩小的方法,但对我来说,这似乎与最初缩小 HTML 大小(运行时速度)的目的背道而驰。

Firstly, whilst I'm aware that gzipping HTML would probably have as much (more?) of a performance gain as minifying HTML - I am certainly intrigued by whether the following technique could work - or if anyone has done something similar.

Having seen some of the work done by others on pre-compiling MVC Razor views, I wondered if it is possible to some-way inject a pre-build event to such a process so that HTML can be minifyed, before then being built into a single DLL?

Or is there another way to minify at build time?

I've seen several people come up with ways of minifying by way of run-time techniques, but to me that seems to be counter to the who purpose of shrinking HTML size in the first place (runtime speed).

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

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

发布评论

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

评论(3

倥絔 2024-11-25 20:22:04

在构建时缩小 Razor 视图没有意义,因为它们不是最终标记。当所有这些助手吐出 HTML 时,您在构建时可能缩小的任何内容都会在运行时被破坏。因此,如果您确实想降低带宽使用量,第一步也是最重要的一步就是 gzip。好处将是巨大的。如果您是一个狂热分子并且想要多抓几个字节,请缩小 HTML 运行时。为此,我会向您推荐 Meleze.Web NuGet

但请记住:无论您做什么,请在发布之前对应用程序进行广泛的负载测试。这样您就会知道什么最适合您。

Minifying Razor views at build time wouldn't make sense as they are not final markup. Whatever you might have minified at build time would be broken at runtime when all those helpers spit their HTML. So if you really want to lower your bandwidth usage the first and foremost step is to gzip. The benefit will be enormous. And if you are a maniac and want to scratch a few more bytes minify the HTML runtime. I would recommend you the Meleze.Web NuGet for this purpose.

But remember: what ever you do, perform extensive load tests of your application before shipping. This way you will know what works best for you.

北恋 2024-11-25 20:22:04

缩小 HTML 代码的效率远低于缩小 JavaScript - 需要减少的元素很少。这就是为什么很少这样做的原因。

Minifyng HTML code is much less effective than minifying JavaScript - very few elements to reduce. That is why it rarely done.

め七分饶幸 2024-11-25 20:22:04

您可以使用RCompressor

免责声明:我是该项目的作者。

You can use RCompressor.

Disclaimer: I'm the author of the project.

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