Reduce file size by shortening URLs and safely removing all standard comments and unnecessary whitespace from an HTML document.
Combining HTML “minification” with cache and HTTP compression (WP Super Cache, or similar) will cut down your bandwidth and ensure near-immediate content delivery while increasing your Google rankings.
This plugin will compress your HTML by shortening URLs and removing standard comments and whitespace; including new lines, carriage returns, tabs and excess spaces. Most importantly, by ignoring <pre>
, <textarea>
, <script>
and Explorer® conditional comment
tags, presentation will not be affected.
Yes, slightly. While you should be using WP Super Cache anyway, it will correct the issue.
No.
Yes.
Probably, however WordPress does a pretty good job of correcting invalid markup. But honestly, it’s your job to make sure that your code doesn’t suck.
If the links in your HTML are not hard-coded as hashes without the use of a script, an issue could occur with URL shortening. If so, setting $shorten_urls
on line 21
of libs/html-minify.php to false
will fix that.
This is totally fine and actually intentional. It’s standard and will not cause 404s nor get in the way of your SEO, but it will lower file size! You might be interested in reading more about this technique, called scheme-relative URLs.
To preserve rendered whitespace. One or more line breaks in your markup are rendered as a single space in a web browser. Visual discrepancies would occur if those line breaks were not converted to at least one space.
While <pre>, <textarea> and <script> tags are automatically left uncompressed, you can designate any code to be exempted from compression. Simply drop your content between a pair of <!--wp-html-compression no compression-->
comment tags. A picture is worth a thousand words; so, check the screenshots.
Until a settings page is created, you’ll have to edit the file from the “Plugins” menu in the WordPress admin. Set $compress_js
on line 21
of libs/html-minify.php to true
. This is not recommended as this plugin is not yet ready to properly compress inline scripts.
Since not every WordPress server supports the installation of PHP extensions, this plugin does not currently make use of HTML Tidy. However, future releases may do so.
This plugin has only been tested with versions of WordPress as early as 3.2. For anything older, you’ll have to see for yourself.
<script>
and <style>
tags are no longer shortened unless compression on such tags has been enabled"#"
) are no longer invalidated by the URL shortener"javascript:"
) are no longer invalidated by the URL shortener"data:"
) are no longer invalidated by the URL shortenerdata
attribute values (common to <object>
)template_redirect
(?)//domain.com/
) are no longer brokenaction
, href
, src
attributesaction
, alt
, content
, src