SkillAgentSearch skills...

Htmlcompressor

HTML Compressor and Minifier, Backup of code.google.com/p/htmlcompressor

Install / Use

/learn @WhiteTrashLord/Htmlcompressor
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<p> Edit: I am not the author of the code. I probably won't maintain this project. I simply wanted to save the code from https://code.google.com/p/htmlcompressor/ for you guys :) </p> <p>HtmlCompressor is a small, fast and very easy to use Java library that minifies given HTML or XML source by removing extra whitespaces, comments and other unneeded characters without breaking the content structure. As a result pages become smaller in size and load faster. A command-line version of the compressor is also available. </p><p>Here is a few samples of HTML compression results with default settings: <table class="wikitable"><tr><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Site Name</strong> </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Original</strong> </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Compressed</strong> </td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>Decrease</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">BBC</td><td style="border: 1px solid #ccc; padding: 5px;">77,054b</td><td style="border: 1px solid #ccc; padding: 5px;">55,324b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>28.2%</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">CNet</td><td style="border: 1px solid #ccc; padding: 5px;">86,492b</td><td style="border: 1px solid #ccc; padding: 5px;">61,896b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>28.4%</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">FOX News</td><td style="border: 1px solid #ccc; padding: 5px;">75,266b</td><td style="border: 1px solid #ccc; padding: 5px;">64,221b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>14.7%</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">GameTrailers </td><td style="border: 1px solid #ccc; padding: 5px;">112,199b</td><td style="border: 1px solid #ccc; padding: 5px;">92,851b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>17.2%</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">Kotaku</td><td style="border: 1px solid #ccc; padding: 5px;">134,938b</td><td style="border: 1px solid #ccc; padding: 5px;">116,280b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>13.8%</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">National Post</td><td style="border: 1px solid #ccc; padding: 5px;">75,006b</td><td style="border: 1px solid #ccc; padding: 5px;">55,628b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>25.8%</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">SlashDot</td><td style="border: 1px solid #ccc; padding: 5px;">158,137b</td><td style="border: 1px solid #ccc; padding: 5px;">142,346b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>10.0%</strong> </td></tr> <tr><td style="border: 1px solid #ccc; padding: 5px;">StackOverflow</td><td style="border: 1px solid #ccc; padding: 5px;">116,032b</td><td style="border: 1px solid #ccc; padding: 5px;">100,478b</td><td style="border: 1px solid #ccc; padding: 5px;"> <strong>13.4%</strong> </td></tr> </table></p><h4><a name="Table_of_Contents"></a>Table of Contents<a href="#Table_of_Contents" class="section_anchor"></a></h4><p><ul><ul><li><a href="#How_it_Works">How it Works</a></li><li><a href="#How_to_Use">How to Use</a></li><ul><li><a href="#For_Java_Projects">For Java Projects</a></li><li><a href="#For_Non-Java_Projects">For Non-Java Projects</a></li><li><a href="#Bad_Practices">Bad Practices</a></li><li><a href="#Known_Issues">Known Issues</a></li></ul><li><a href="#Dependencies">Dependencies</a></li><li><a href="#Compressing_HTML_and_XML_files_from_a_command_line">Compressing HTML and XML files from a command line</a></li><ul><li><a href="#Defining_custom_preservation_rules">Defining custom preservation rules</a></li><li><a href="#Compressing_whole_directories_and_multiple_files_at_once">Compressing whole directories and multiple files at once</a></li><li><a href="#HTML_Analyzer">HTML Analyzer</a></li></ul><li><a href="#Using_HTML_Compressor_from_Java_API">Using HTML Compressor from Java API</a></li><ul><li><a href="#Creating_your_own_block_preservation_rules">Creating your own block preservation rules</a></li><li><a href="#Using_different_and_CSS_compressor_implementations">Using different and CSS compressor implementations</a></li><li><a href="#Retrieving_HTML_compression_statistics">Retrieving HTML compression statistics</a></li></ul><li><a href="#Using_XML_Compressor_from_Java_API">Using XML Compressor from Java API</a></li><li><a href="#Compressing_selective_content_in_JSP_pages">Compressing selective content in JSP pages</a></li><ul><li><a href="#Taglib_installation_procedure">Taglib installation procedure</a></li><li><a href="#Using_compressor_taglib">Using compressor taglib</a></li></ul><li><a href="#Compressing_selective_content_in_Velocity_templates">Compressing selective content in Velocity templates</a></li><ul><li><a href="#Compressor_directive_installation_procedure">Compressor directive installation procedure</a></li><li><a href="#Using_compressor_directives">Using compressor directives</a></li></ul><li><a href="#Setting_up_Ant_task_to_compress_files">Setting up Ant task to compress files</a></li><li><a href="#Maven_Integration">Maven Integration</a></li><ul><li><a href="#Maven_Artifact">Maven Artifact</a></li><li><a href="#Maven_Plugin">Maven Plugin</a></li></ul><li><a href="#Who_Uses_it">Who Uses it</a></li></ul></ul> </p><h2><a name="How_it_Works"></a>How it Works<a href="#How_it_Works" class="section_anchor"></a></h2><p>During HTML compression the following is applied to the page source: <ul><li>Any content within <tt>&lt;pre&gt;</tt>, <tt>&lt;textarea&gt;</tt>, <tt>&lt;script&gt;</tt> and <tt>&lt;style&gt;</tt> tags will be preserved and remain untouched (with the exception of <tt>&lt;script type=&quot;text/x-jquery-tmpl&quot;&gt;</tt> tags which are compressed as HTML). Inline javascript inside tags (<tt>onclick=&quot;test()&quot;</tt>) will be preserved as well. You can wrap any part of the page in <tt>&lt;!-- {{{ --&gt;...&lt;!-- }}} --&gt;</tt> comments to preserve it, or provide a set of your own preservation rules (out of the box <tt>&lt;?php...?&gt;</tt>, <tt>&lt;%...%&gt;</tt>, and <tt>&lt;!--#... --&gt;</tt> are also supported) </li><li>Comments are removed (except IE conditional comments). Could be disabled. </li><li>Multiple spaces are replaced with a single space. Could be disabled. </li><li>Unneeded spaces inside tags (around <tt>=</tt> and before <tt>/&gt;</tt>) are removed. </li><li>Quotes around tag attributes could be removed when safe (off by default). </li><li>All spaces between tags could be removed (off by default). </li><li>Spaces around selected tags could be removed (off by default). </li><li>Existing doctype declaration could be replaced with simple <tt>&lt;!DOCTYPE html&gt;</tt> declaration (off by default). </li><li>Default attributes from <tt>&lt;script&gt;</tt>, <tt>&lt;style&gt;</tt>, <tt>&lt;link&gt;</tt>, <tt>&lt;form&gt;</tt>, <tt>&lt;input&gt;</tt> tags could be removed (off by default). </li><li>Values from boolean tag attributes could be removed (off by default). </li><li><tt>javascript:</tt> pseudo-protocol could be removed from inline event handlers (off by default). </li><li><tt>http://</tt> and <tt>https://</tt> protocols could be replaced with <tt>//</tt> inside <tt>href</tt>, <tt>src</tt>, <tt>cite</tt>, and <tt>action</tt> tag attributes (tags marked with <tt>rel=&quot;external&quot;</tt> are skipped). </li><li>Content inside <tt>&lt;style&gt;</tt> tags could be optionally compressed using YUI compressor or your own compressor implementation. </li><li>Content inside <tt>&lt;script&gt;</tt> could be optionally compressed using YUI compressor, Google Closure Compiler or your own compressor implementation. </li></ul></p><p>With default settings your compressed HTML layout should be 100% identical to the original in all browsers (only characters that are completely safe to remove are removed). Optional settings (that should be safe in 99% cases) would give you extra savings. </p><p>You can optionally remove all unnecessary quotes from tag attributes (attributes that consist from a single word: <tt>&lt;div id=&quot;example&quot;&gt;</tt> would become <tt>&lt;div id=example&gt;</tt>). This usually gives around 3% pagesize decrease at no performance cost but might break strict HTML validation so this option is disabled by default. </p><p>About extra 3% pagesize can be saved by removing inter-tag spaces. It is fairly safe to turn this option on unless you rely on spaces for page formatting. Even if you do, you can always preserve required spaces with <tt>&amp;#20;</tt> or <tt>&amp;nbsp;</tt>. This option has no performance impact. </p><p>You can quickly test how each of the compressor settings would affect filesize of your page by running command line <a href="#HTML_Analyzer">HTML Analyzer</a>. </p><p>During XML compression: <ul><li>Any content inside <tt>&lt;![CDATA[...]]&gt;</tt> is preserved. </li><li>All comments are removed. Could be disabled. </li><li>All spaces between tags are removed. Could be disabled. </li><li>Unneeded spaces inside tags (multiple spaces, spaces around <tt>=</tt>, spaces before <tt>/&gt;</tt>) are removed. </li></ul></p><h2><a name="How_to_Use"></a>How to Use<a href="#How_to_Use" class="section_anchor"></a></h2><p>Before reading further, if you are not serving your HTML/XML content using GZip compression, you should really look into that first, as it would give you very significant compression ratio (sometimes up to 10 times) and usually very easy to implement. For further reading on GZip compression please see <a href="http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/" rel="nofollow">this article</a> for example. </p><p>If you want to reach further size dec

Related Skills

View on GitHub
GitHub Stars4
CategoryDevelopment
Updated5y ago
Forks2

Languages

Java

Security Score

70/100

Audited on Aug 7, 2020

No findings