Minimizing HTML is probably not a big deal for Stackoverflow. I did a little test based on the HTML source on the main page.
Raw content length: 207454 bytes
Gzipped content length: 30915 bytes
Trimmed content length: 176354 bytes
Trimmed and gzipped content length: 29658 bytes
SO already uses GZIP compression, so trimming spaces (in fact, mining HTML or "HTML compression", as you call it) will save "only" about 1 KB of bandwidth per response. For giants with more than 1 million page views per day, HTML minification will already save more than 1 GB of bandwidth per day (in fact, SO will also save). Google serves billions of page views per day, and each byte of difference will save gigabytes per day.
FWIW, I used this simple quick'n'dirty Java application to test it:
package com.stackoverflow.q2424952; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.zip.GZIPOutputStream; public class Test { public static void main(String... args) throws IOException { InputStream input = new URL("http://stackoverflow.com").openStream(); byte[] raw = raw(input); System.out.println("Raw content length: " + raw.length + " bytes"); byte[] gzipped = gzip(new ByteArrayInputStream(raw)); System.out.println("Gzipped content length: " + gzipped.length + " bytes"); byte[] trimmed = trim(new ByteArrayInputStream(raw)); System.out.println("Trimmed content length: " + trimmed.length + " bytes"); byte[] trimmedAndGzipped = gzip(new ByteArrayInputStream(trimmed)); System.out.println("Trimmed and gzipped content length: " + trimmedAndGzipped.length + " bytes"); } public static byte[] raw(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (int data; (data = input.read()) != -1; output.write(data)); input.close(); output.close(); return output.toByteArray(); } public static byte[] gzip(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(output); for (int data; (data = input.read()) != -1; gzip.write(data)); input.close(); gzip.close(); return output.toByteArray(); } public static byte[] trim(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); for (String line; (line = reader.readLine()) != null;) output.write(line.trim().getBytes()); reader.close(); output.close(); return output.toByteArray(); } }
source share