Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 800
isNaN1247 Avatar asked Jul 08 '11 10:07

isNaN1247


1 Answers

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.

like image 161
Darin Dimitrov Avatar answered Sep 29 '22 11:09

Darin Dimitrov