tags:

views:

57

answers:

2

Is there any way to decrease or squish the size of a .html page?

+1  A: 

Assuming you are talking about the length of the page in bytes:

  • Make sure gzip is enabled on your server.
  • Remove comments.
  • Remove any Javascript and css - Javascript can be compressed in a separate file using a tool such as googles closure compiler.
  • Use ansi ascii or UTF8 encoding (as opposed to UCS2/UTF-16).
CiscoIPPhone
+1  A: 

If we are talking about size of the file in bytes, then gzipping it on-the-fly will have the biggest impact. After that, I'd suggest removing whitespaces and comments, and moving all inline javascript and css into separate files. Then you may consider trying to clean the HTML a bit, like removing tables in favor of divs and all that.

Then, if you are really going to push the limits, you may try to change your doctype to HTML4 Transitional and then exploit its un-strictness. You can remove <body> tag, you can stop closing <li>s and <td>s, you can drop off parentheses around tag attributes or remove whitespaces between them, and still remain valid. Also, if you replace all your <strong>s with <b>s, you can save up to 10 symbols per pair! :)

If you need a working example of that "pushing the limits" techniques, then go to http://yandex.ru and explore their sources. Yandex is the leading search engine in Russia, they really care about the size of their index page and they know a lot about optimizing the code and load speed of pages.

n1313