rehansaeed.github.io icon indicating copy to clipboard operation
rehansaeed.github.io copied to clipboard

[Comment] Minifying HTML for ASP.NET MVC

Open RehanSaeed opened this issue 5 years ago • 6 comments

https://rehansaeed.com/minifying-html-for-asp-net-mvc/

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Josh Olson Josh Olson commented on 2016-02-19 02:55:16

I'm pretty sure your conclusion is right: you're off by a decimal point or two. One reason is the arithmetic and another is conceptual.

First, the arithmetic. Forgive me if I followed you incorrectly but this is what I'm seeing. We got 1 zettabyte (1000 exabytes) of traffic. Since we're using the SI zetta instead of the IEC zebi, I'll stick to that throughout. 1 zettabyte = 1,000,000,000 terabytes. Using your ratio of 57KB / 2162KB, that's 26,364,477.3 terabytes. Compare that to your 257,465 terabytes. What am I missing? ... I don't think anything based on the information you're providing me. If I'm right, your methodology would conclude even more bandwidth would be wasted. However...

Conceptually, you missed something huge. Global IP Traffic != Global HTTP Traffic. I highly doubt HTTP traffic comes anywhere close to BitTorrent traffic, Netflix, YouTube (HTTP but the ratio is probably closer to 57KB/100MB), video games, etc.

Regardless, I'm all for minifying. :-)

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2016-02-19 10:21:38

I'm pretty sure your conclusion is right: you're off by a decimal point or two. One reason is the arithmetic and another is conceptual.

First, the arithmetic. Forgive me if I followed you incorrectly but this is what I'm seeing. We got 1 zettabyte (1000 exabytes) of traffic. Since we're using the SI zetta instead of the IEC zebi, I'll stick to that throughout. 1 zettabyte = 1,000,000,000 terabytes. Using your ratio of 57KB / 2162KB, that's 26,364,477.3 terabytes. Compare that to your 257,465 terabytes. What am I missing? ... I don't think anything based on the information you're providing me. If I'm right, your methodology would conclude even more bandwidth would be wasted. However...

Conceptually, you missed something huge. Global IP Traffic != Global HTTP Traffic. I highly doubt HTTP traffic comes anywhere close to BitTorrent traffic, Netflix, YouTube (HTTP but the ratio is probably closer to 57KB/100MB), video games, etc.

Regardless, I'm all for minifying. :-)

Yes the numbers are very rough. I had to go out and discover certain basic facts which I could base my math on. It turns out that it's pretty hard to do and we just don't know what global internet usage really amounts to.

My intention with this blog post was to spur the ASP.NET developers into action and show how amazing it would be to add a HTML minification feature, make it super easy to use and turn it on by default. So far, I haven't got any really good vibes but I'm hoping the next version will answer this question.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Flo Flo commented on 2016-03-08 11:41:37

How is guaranteed that these tools/plugins/libs/etc. are not breaking complex views, esp. Razor syntax can get very "special"? Using such thingy without having it written on your own makes you testing the whole app/website again, i'd say?

Nontheless, the performance gains esp. for mobile sites are awesome...

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2016-03-08 12:10:59

How is guaranteed that these tools/plugins/libs/etc. are not breaking complex views, esp. Razor syntax can get very "special"? Using such thingy without having it written on your own makes you testing the whole app/website again, i'd say?

Nontheless, the performance gains esp. for mobile sites are awesome...

That's why this feature is totally experimental. That said, it really is doing very little and does 80% of the minification work, while still not breaking anything in my testing. The minified razor is there for you to look at, so you could make your own adjustments to fix something if it was not quite right, although that is not ideal. There are a lot of other more complex things that can be done for HTML minification, such as changing checked="true" to just checked.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Tom Pažourek Tom Pažourek commented on 2017-11-17 08:36:00

I recently built a very trivial and tiny HTML minifier for Razor that's easy to set up (just change the factory in the Web.config file), works in compile-time, and doesn't do any special minification magic. It just basically replaces multiple spaces with one. From my testing, whitespace is the biggest issue in HTML files, and this fixes just that (so side-effects should be minimal). If anybody's interested in some easy-to-use and simple solution, check it out (it's literally less than 100 lines of code):

https://github.com/tompazourek/RazorHtmlMinifier.Mvc5

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

SEO SEO commented on 2018-04-07 08:06:04

Great, thank you for sharing this article.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed