0

I am deploying a web application and I am able to compress CSS and js in my web application using page speed module in nginx/apache, but couldn't able to remove HTML white space.

Does anyone has done this before, I have seen this implementation in a major website such as LinkedIn Facebook, and Google.

Does removing white space in HTML add performance boost? As per my understanding removing whitespace reduces some extra bytes.

Here is an example of a condensed version of HTML page from google.

enter image description here

shining
  • 1,049
  • 16
  • 31
  • If you do a on the fly removal of white spaces, then maybe considering a on the fly compression with gzip is more efficient than removing the white spaces. This gets mentioned in this comment: https://serverfault.com/questions/222406/nginx-auto-minify-html-output#361802 – soulflyman Jan 31 '18 at 10:17

2 Answers2

0

You can use tools like https://www.textfixer.com/html/compress-html-compression.php

If you use a text editor like atom or vscode you might as well look for a plugin that does that for you.

It doesn't really affect much on the performance, as you said it will reduce some bytes, but as I suspect you're not building something as big as an Amazon site it doesn't quite matter, moreover it will be a pain to read the code.

Emerson Lopes
  • 119
  • 1
  • 10
0

Does removing white space in HTML add performance boost?

Unlikely will you benefit much given that gzip is enabled for your site. The more you save during such a stripping phase the less benefit you would gain from gzipping and vice versa.

BTW, mod_pagespeed has the collapsible module doing what you're asking.

If mod_pagespeed doesn't meet your requirements

Multiple options

  • if you have a static html pages that just need to be returned to the user it's quite easy to do in offline mode
  • you can also do it at backend level using your framework batteries. I.e. in case you use a python framework this module could be used

django-html is an HTML minifier for Python, with full support for HTML 5. It supports Django, Flask and many other Python web frameworks. It also provides a command line tool, that can be used for static websites or deployment scripts.

  • if none of the options above are viable use some 3rd party modules doing it at nginx level

  • depending on your needs you might also consider services like cloudflare

Oleg Kuralenko
  • 11,003
  • 1
  • 30
  • 40