Hey, I was just wondering if there was anyone here who likes to compress html code, what I mean is filtering out line breaks and tabs. What I like to do is have the code neat and indented before I parse it so it looks like this: <table> <tr> <td> Dog </td> </tr> </table> HTML: and then after it gets parsed the browser source code looks like this, prety much the entire html document, head and all(Since I don't give two flying shits what the code looks like in the browser source code, only what it looks like in my workspace file) This cuts the document size almost in half: <table><tr><td>Dog</td></tr></table> HTML: What I do is this: function compress($buffer) { $getrid = array("\n","\r", " "); return str_replace($getrid,"",$buffer); } ob_start("compress"); //html here ob_end_flush(); PHP: works really good.
Certainly wouldnt do it at run time - why add server load for something that is quick and easy to do yourself? As we almost exclusively develop .Net dynamic sites and with how .Net works with controls there is typically little actual real HTML in our projects to compress. Personally would rather see the output HTML laid out fairly neatly than add a relatively small amount of bandwidth by using carriage returns.
Nope - it makes the HTML code harder to read. Besides, when using clean, minimal, semantic and valid markup with the CSS and scripting files separated from the Web page (and called externally), the "savings" from compressing the HTML (or other files) would be minimal at best. If you really want to optimize and minimize your file sizes, look into optimizing your images, especially those called via CSS.
good point, if we minimize as much html code as posible and substitute it for css(or classes) so the css can be used over and over again than lots of file size is being spared in the long run. example <table cellspacing="0" cellpadding="0" bgcolor="white" border="0" align="center"> <tr> <td valign="top" align="center" bgcolor="grey"> <b> Header </b> </td> </tr> <tr> <td valign="top" align="center" bgcolor="blue"> <p> text yo </p> </td> </tr> </table> HTML: vs <table class="Box"> <tr> <td class="BoxHeader"> Header </td> </tr> <tr> <td> <!-- use child elements --> text here yo........... </td> </tr> </table> HTML: The way I see it is any thing that is used once is an id/template elements... anything that is used over and over should be a class/text styles etc. <body id="Main"> <div class="Error"> Error: invalid submit button </div>
In which case I'd just remove the layout tables and use clean, minimal, semantic and valid HTML instead, separating all the structure from the presentation and behavior, and use external stylesheets and scripts for my CSS and JavaScript files.
Have you considered using gzip compression instead? The file size will be much smaller than by simply removing whitespace.
Their isn't any point, how many dialup connections do you get accessing your site? The only thing that slows down my site is the damn servers.
420 so far this month (out of 14000 odd visitors) So yes it does matter to some people But I don't compress code like that, image optimisation + clean code works well enough.
Even on a fast internet connection the effects of content compression are noticeable, that's why I compress all files including Javascript, CSS, and XML. If your server struggles to keep up with the amount of traffic you're getting, then yes I agree that compressing content on the fly isn't a good idea. But for most sites, server speed isn't such an issue.
Don't compress on-the-fly. Compress on deployment. Use Apache Ant or Maven or whatever in order to compress HTML, CSS, JS BEFORE deployment!
I'm a dial up user but compressing html really doesn't make a significant difference, unless its a stupid size. Your viewers will be spending more time loading outside sources like adsense etc.