Who is compressing their HTML?

Even Qaru does not compress its HTML . Is HTML compression recommended? As far as I saw, it looks like Google is the only one .... (view source). Why not this standard practice?

+4
source share
5 answers

I think you are confusing HTML minimization and GZIP compression. The latter is quite common (for example, using mod_gzip in Apache, the article here ), and in most cases this should be enough. This is completely internal between the server and the browser; you cannot see it in the source code.

Actual minimization of HTML should not be done, except for sites where the stored byte can mean tens of thousands of dollars in saving traffic (for example, for Google.)

+12
source

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(); } } 
+2
source

Another important reason not to minimize your code is training. I like the ability to browse and view the source code of people to see how they solve problems, and I keep my source in full form so that others can look at mine. I still have gzip compressed code before it is sent to the browser, but when it arrives it will be uncompressed in full form and fully readable.

+1
source

I think few people do this. Too much work, too little gain, especailly, as the HTTP payload can be zip compressed these days.

0
source

Gzip compression, which every modern web server and web server makes HTML compression (minimization) useless or almost immaterial.

Therefore, very few use this.

0
source

Source: https://habr.com/ru/post/1303788/


All Articles