开发者

ASP.Net MVC Razor Views - Minifying HTML at build time

开发者 https://www.devze.com 2023-03-19 07:18 出处:网络
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

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 mini开发者_StackOverflowfy 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).


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.


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


You can use RCompressor.

Disclaimer: I'm the author of the project.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号