Currently I am using a system where HTML gets cached server-side before it's sent to the browser. I'm looking to compress the HTML source of my website before it is cached.

Basically I'm looking for an open-source (preferably PHP) HTML compressor able to handle HTML 5, any ideas?

  • Can you not enable gzip compression server side? – toomanyairmiles May 22 '12 at 15:34
  • I'm talking about a process that would compress the HTML source before gzipping it, making the gzipped result even smaller (removing HTML comments, collapsing whitespace, ...). – Bart May 22 '12 at 15:37
  • Ah, you're talking about minification rather than compression! – toomanyairmiles May 22 '12 at 15:39
  • Yes, although both terms seem to be used when it comes to HTML. – Bart May 22 '12 at 15:41
  • Fixed title to clarify. – Bart May 22 '12 at 15:43

The question here is why you would need to minify html, gzip should be fine on its own, the biggest single cost in front end speed is http requests at the server end and images in terms of pure bandwidth. HTML is so small it's barely worth the effort.

I would suggest using tools like Google Page Speed or Yahoo!'s YSlow (and reading Yahoo!'s research on the topic) to see where the problems are before you minify code - IMHO it's not a very reliable process and is more likely to cause problems with cross browser compatibility down the line.

This answer at StackOverFlow covers minification in some detail.

| improve this answer | |
  • 1
    Whether or not I need a HTML minifier isn't the question here, depending on what you're serving HTML might be a big portion of used bandwith. – Bart May 22 '12 at 15:49
  • @Bart Sure, the better answer is over at SO, as this is really a scripting question. I've seen some very large pages and very big scripts (javascript is a different box of frogs), even minified the actual saving in terms of optimal load time is so small its quite insignificant compared to the overall volume of http requests (this is the webmaster answer)... – toomanyairmiles May 22 '12 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.