tags:

views:

8961

answers:

9
+8  Q: 

Html minification?

Is there any online tool that we can input the html source of a page and it will minify the code?

I would do that for aspx files that are not a good idea to make the webserver gzip them...

thanks!

A: 

http://www.digitaloverload.co.uk/jsmin/

and the code for it can be found at http://code.google.com/p/jsmin-php/

perhaps modifying that for html would work? I did spent a short amount of time on google, but nothing showed up for html :/ perhaps you coudld make us all love you and be the first ^_^

Fusspawn
This is Jaavscript Minifier, not an HTML minifer
Julien
this was posted nearly a year ago >.>, Also i did mention it would need to be modified for html at the time.
Fusspawn
+4  A: 

CodeProject has a published sample project (http://www.codeproject.com/KB/aspnet/AspNetOptimizer.aspx?fid=1528916&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2794900) to handle some of the following situations...

  • Combining ScriptResource.axd calls into a single call
  • Compress all client side scripts based on the browser capability including gzip/deflate
  • A ScriptMinifier to remove comments, indentations, and line breaks.
  • An HTML compressor to compress all html markup based on the browser capability including gzip/deflate.
  • And - most importantly - an HTML Minifier to write complete html into single line and minify it at possible level (under construction).
The Lazy DBA
+10  A: 

Don't do this. Or rather, if you insist on it, do it after any more significant site optimizations are complete. Chances are very high that the cost/benefit for this effort is negligible, especially if you were planning to manually use online tools to deal with each page.

Use YSlow or Page Speed to determine what you really need to do to optimize your pages. My guess is that reducing bytes of HTML will not be your site's biggest problem. It's much more likely that compression, cache management, image optimization, etc will make a bigger difference to the performance of your site overall. Those tools will show you what the biggest problems are -- if you've dealt with them all and still find that HTML minification makes a significant difference, go for it.

Zac Thompson
What is wrong with optimization if minified code is easy to read using automated beautification?
It probably isn't the biggest problem - but if it's a trivial process to run markup through a minifying set of regex's when compiling from dev to qa or prod, then why wouldn't you want to send out smaller markup documents?
Will Peavy
Not actually an answer to the original question :(
Django Reinhardt
+2  A: 

I wrote a web tool to minify HTML. http://mailmarkup.org/prettydiff/prettydiff.html

+2  A: 

HTML Tidy

But I agree with @Zac - speed up by using YSlow.

Martin
+8  A: 

try http://code.google.com/p/htmlcompressor/

+3  A: 

This worked for me:

http://code.google.com/p/minify/source/browse/trunk/min/lib/Minify/HTML.php

It's not an already available online tool, but being a simple PHP include it's easy enough you can just run it yourself.

I would not save compressed files though, do this dynamically if you really have to, and it's always a better idea to enable Gzip server compression. I don't know how involved that is in IIS/.Net, but in PHP it's as trivial as adding one line to the global include file

Infinity
+3  A: 

Is there any online tool that we can input the html source of a page and it will minify the code?

Yes: http://willpeavy.net/minifier/

Will Peavy
Simple at what I was looking for.
PlanetUnknown
+1  A: 

This seems to be pretty interesting: http://perfectionkills.com/experimenting-with-html-minifier/

http://kangax.github.com/html-minifier/

StefanS