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

时间:2022-10-19 21:27:00

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.

首先,虽然我知道gzipping HTML可能会像缩小HTML一样(更多?)获得性能提升 - 我当然对以下技术是否可行 - 或者是否有人做过类似工作感到好奇。

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?

看过其他人在预编译MVC Razor视图时所做的一些工作,我想知道是否有可能以某种方式将预构建事件注入到这样的进程中,以便可以缩小HTML,然后将其构建到单个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).

我已经看到有几个人想出了通过运行时技术缩小的方法,但对我而言,这似乎与首先缩小HTML大小的目的(运行时速度)背道而驰。

3 个解决方案

#1


8  

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.

在构建时缩小Razor视图是没有意义的,因为它们不是最终标记。无论你在构建时缩小什么,都会在运行时被打破,当所有帮助者都吐出他们的HTML时。因此,如果您真的想降低带宽使用率,那么首要的步骤就是gzip。好处将是巨大的。如果你是一个疯子,并想要刮几个字节缩小HTML运行时。为此,我会向你推荐Meleze.Web NuGet。

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.

但请记住:无论您做什么,在发货前都要对您的应用程序进行大量的负载测试。这样你就会知道什么最适合你。

#2


1  

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

Minifyng HTML代码远比缩小JavaScript有效 - 很少有元素可以减少。这就是它很少这样做的原因。

#3


0  

You can use RCompressor.

您可以使用RCompressor。

Disclaimer: I'm the author of the project.

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

#1


8  

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.

在构建时缩小Razor视图是没有意义的,因为它们不是最终标记。无论你在构建时缩小什么,都会在运行时被打破,当所有帮助者都吐出他们的HTML时。因此,如果您真的想降低带宽使用率,那么首要的步骤就是gzip。好处将是巨大的。如果你是一个疯子,并想要刮几个字节缩小HTML运行时。为此,我会向你推荐Meleze.Web NuGet。

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.

但请记住:无论您做什么,在发货前都要对您的应用程序进行大量的负载测试。这样你就会知道什么最适合你。

#2


1  

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

Minifyng HTML代码远比缩小JavaScript有效 - 很少有元素可以减少。这就是它很少这样做的原因。

#3


0  

You can use RCompressor.

您可以使用RCompressor。

Disclaimer: I'm the author of the project.

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