20

Does anyone know of a good online generator to take the source code of an HTML page and compress/minimize the entire page.

Meaning, compress/minimize all embedded CSS, JavaScript and obviously the HTML of that web page while also removing unneeded HTML/CSS/JavaScript comments, spaces, tabs, etc?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Ted
  • 217
  • 1
  • 2
  • 3
  • 1
    I wouldn't worry too much about minification. Make sure you at least gzip your output first, as that will make a much bigger difference. – DisgruntledGoat Nov 01 '09 at 17:09
  • 4
    @Disgruntled: It's a both/and situation. For best results, you minify *and* gzip. Not minifying means all your comments go public, or you don't write comments, both of which fall into the Bad Idea category. – T.J. Crowder Jul 02 '11 at 10:46
  • @T.J. Crowder: Sure. I just wanted to point out that gzip is significantly more important than minification, at least order of magnitude so. The difference between gzip alone and minify+gzip is almost nothing. – DisgruntledGoat Jul 03 '11 at 22:11
  • 1
    @Disgruntled: I don't think the relative merit is anything *like* that. Take jQuery. Unminified, uncompressed it's 236,202 bytes (v1.6.2). Just minified it's 91,556 (38.76%). Just gzipped it's 68,405 as delivered via Google's CDN (28.96%) (using Google's because command-line gzip will do *slightly* better). Nothing like an order of magnitude difference between those two. (And of course, what we want is both: 32,178 [13.62%]). – T.J. Crowder Jul 04 '11 at 00:45
  • @T.J. Crowder: The difference is that in jquery, every function and property name can be renamed, in most cases turning an 8 or 9 or even 14 or 15 letter long function name into a 1 letter function name. HTML can not be compressed like that. tag names and property names and ids must all remain the same. – Noishe Jan 13 '14 at 07:34
  • @Noishe: Absolutely, HTML can't be minified nearly as much as JavaScript, and CSS lies somewhere in the middle. Note that the question is asking about minifying all three. Also, again: Comments. :-) – T.J. Crowder Jan 13 '14 at 08:08

9 Answers9

12

Juriy Zaytsev wrote an HTML minifier in JavaScript, which you can use online on this page: http://kangax.github.com/html-minifier/

As the warning says, it’s still an early alpha, so there might be bugs. Use with caution!

Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
6

http://prettydiff.com/ - This is written in JavaScript so you can use it instantly in your browser.

austincheney
  • 807
  • 10
  • 9
BillW
  • 61
  • 1
  • 2
    Doesn't remove comments, and still leaves in a fair bit of unnecessary whitespace (such as line breaks). – T.J. Crowder May 22 '10 at 15:29
  • @T.J. Crowder - It does remove comments and the remaining white space is necessary. Please read the documentation for an explanation why. – austincheney Jul 01 '11 at 17:35
  • Hey @Austin, good to see you here. The tool I commented on at the time did not remove comments (I tested) and left unnecessary linebreaks (in fact, in JS sans comments, there are **no** necessary linebreaks; only necessary semicolons). The tool now looks quite different, and does indeed remove comments and linebreaks. Sadly, it removes linebreaks in places where they affect semicolon insertion without inserting the necessary semicolons -- and thus changes the code. [Example](http://jsbin.com/edurud0). *(Not dissing.)* I love the idea of a meaningful diff tool, looks very useful. Best with it, – T.J. Crowder Jul 02 '11 at 08:33
  • Automatic semicolon insertion added! – austincheney Dec 13 '11 at 12:20
4

There's an online compressor that does minimize all embedded CSS and JavaScript blocks and also the HTML. It produces a single line output code which renders as the original and respects the document structure.

It uses Yahoo YUI Compressor and Google Closure compiler for JavaScript.

Check it here: HTMLcompressor.com

Tamas
  • 41
  • 1
3

This is the best minifier I found till date.

Check it here: Html, Javascript as well as CSS minifier

kapa
  • 77,694
  • 21
  • 158
  • 175
Zubarik
  • 107
  • 1
  • 2
  • 9
0

I came across a script that will minify your HTML, Inline CSS, Inline Javascript On The Fly.

Check here Dynamic Website Compressor

Basic Bridge
  • 1,881
  • 4
  • 25
  • 37
0

I recommend you to try WebMarkupMin Online.

Andrey Taritsyn
  • 1,286
  • 11
  • 26
0

These are the perfect minifiers:

For Javascript http://javascript-minifier.com/

For CSS http://cssminifier.com/

For PNG http://pngcrush.com/

For JPEG http://jpgoptimiser.com/

Prakash
  • 741
  • 1
  • 7
  • 11
0

I use HTML JavaScript CSS Minifier for minify the entire HTML code (including CSS and Javascript).

You can also encrypt the Javascript parts on Javascript minifier encryptor to make it less readable but it increase the size of your file.

0

A duplicate of https://stackoverflow.com/questions/728260/html-minification ?

And if you do not really need an ON-Line tool, then PageSpeed plugin for Firefox and the Yahho compressor are both really good minifiers. Also the PageSpeed tool can give you hints what to change, and which change will give the biggest change in speed/size.

Community
  • 1
  • 1
bartosz.r
  • 454
  • 4
  • 10