This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16161|Reply: 0

[ASP.NET] Is it really necessary to remove whitespace characters from HTML?

[Copy link]
Posted on 4/29/2019 1:52:08 PM | | |
Just now, a friend asked me on MSN that there are many blank characters on his page, and when I opened the source file, I found that the code was very sparse. He felt it was a waste and said there was a way to get rid of them. I asked him "Is your page compressed with GZip?" He said he used it, so I replied, "Then you don't need to remove the blank characters, the continuous spaces are well compressed, and the effect is not great after removing them." At this time, I couldn't help but think that there was also a section in the morning "Blog Park Homepage Optimization Experience" that was "removing spaces and blank lines in HTML", so I planned to try it to see how effective it was to remove white spaces.

"Blog Park Homepage Optimization Experience":The hyperlink login is visible.

My experimental goal is the detail pages of the first 40 articles on my blog, which range from 98K to 277K before compression, which I think is a typical page size in a blog garden. I use test code like this:

In the above code, I used the method of removing whitespace characters from Bloggarden, and the result is as follows:


Original pageOriginal page (compressed)After removing the blanksAfter Blank (Compressed)Before and after removing the blanksBefore and after blanking (compression)
1307603601811735434702134061316
2559356340624043361870155021536
2788718679426370485298151671496
2212485314820544051548158081600
1516124026013793938940136731320
1350193600012159334750134261250
1282393623011465834878135811352
1615304277614718941392143411384
99884283728704727084128371288
1735344372415844642272150881452
1915195039817695848888145611510
1769964027416270638978142901296
2063484736219140045964149481398
1370143860812285537076141591532
1447153726013109735748136181512
1465313670413261935302139121402
1999154922418222747452176881772
106929298509369028518132391332
1362643666412154834990147161674
1487503799013456736578141831412
2828867192426633670306165501618
1760994146816132240126147771342
108394304569542829216129661240
1525784018613854338866140351320
2302435997021538958554148541416
2511835715623486255694163211462
1969574817618160846776153491400
1722674134015810540056141621284
2658776365024897462142169031508
1474033889413375137492136521402
1490913646013499835190140931270
1677414320015361441856141271344
1715644089815733339648142311250
1258123457011104733200147651370
1906494652417519745040154521484
1538073946213940138054144061408
1207883222810753430930132541298
1633274111014876339710145641400
103101294769028428222128171254
1413843978412664138350147431434

It is worth paying attention to the last two columns, from which we can find that although the page volume can be reduced by more than a dozen K before and after removing the blanks, butAfter compression, the difference is actually only 1-2K - about 1-2 packets。 Are these savings worth it? Furthermore, Blog Garden's practice is to replace the content of each page with regular expressions, so is it worth the cost? This is up to the blog garden to profil itself......

Finally, in fact, removing whitespace characters is not such a simple thing. The simplest example is: Have you come across some HTML editors or RSS readers that turn an otherwise neat code into a line in an article? This is because they arbitrarily remove all whitespace, but forgot that there is an HTML tag called <pre/>......




Previous:Let the numbers show the SQL of the words
Next:The HttpListener writes bytes to the stream beyond the specified Content-Length byte size
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com