這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

WP-HTML-Compression

外掛說明

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.

螢幕擷圖

  • This is what the XHTML looks like after being compressed with WP-HTML-Compression.
  • This is what the same XHTML from the above screenshot looked like prior to compression.
  • This is an example of how to use the compression override.

安裝方式

  1. Download the plugin (zip file).
  2. Upload and activate the plugin through the “Plugins” menu in the WordPress admin.

常見問題集

Installation Instructions
  1. Download the plugin (zip file).
  2. Upload and activate the plugin through the “Plugins” menu in the WordPress admin.
Will this plugin slow down my page load times?

Yes, slightly. While you should be using WP Super Cache anyway, it will correct the issue.

Will Internet Explorer conditional comments be removed?

No.

Is this plugin HTML5-compatible?

Yes.

Will having invalid HTML cause an issue?

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.

Will this plugin interfere with my hash-based JavaScript navigation?

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.

My URLs have the “http:” and/or “https:” stripped??

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.

Why does my compressed HTML have a space between most tags?

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.

How do I mark areas that should not be compressed?

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.

How do I compress the contents of <script> tags?

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.

Are you or have you thought of using HTML Tidy?

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.

Will this plugin work for WordPress version x.x.x?

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.

使用者評論

這個外掛目前沒有任何使用者評論。

參與者及開發者

以下人員參與了開源軟體〈WP-HTML-Compression〉的開發相關工作。

參與者

將 WP-HTML-Compression 外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

0.5.8

  • URLs within <script> and <style> tags are no longer shortened unless compression on such tags has been enabled

0.5.7

0.5.6

  • Upgraded to Absolute-to-Relative URLs v0.3.3
  • Javascript URIs ("javascript:") are no longer invalidated by the URL shortener
  • Minor cleanup

0.5.5.1

  • Oops, minor slip-up

0.5.5

  • Upgraded to Absolute-to-Relative URLs v0.3.2
  • Data URIs ("data:") are no longer invalidated by the URL shortener
  • URL shortener now applied to data attribute values (common to <object>)
  • Minor bug prevention

0.5.4.2

  • PHP errors hidden if/when plugin file is accessed directly

0.5.4.1

  • Fixed typo on variable

0.5.4

  • Plugin should always load now, even for installations that seem to skip the execution of template_redirect (?)
  • Converted for use in standard PHP as HTML Minify, for which this plugin now simply wraps
  • Compression statistics comment disabled by default

0.5.3

  • Bypasses compression for robots.txt
  • Corrected “invalid plugin header” issue when activating from install screen

0.5.2

0.5.1

  • Upgraded to Absolute-to-Relative URLs v0.3
  • JavaScript library references with scheme-relative URLs (//domain.com/) are no longer broken
  • Canonical URL no longer shortened
  • Minor bug fixes

0.5

  • Includes Absolute-to-Relative URLs for action, href, src attributes
  • Bypasses compression for RSS/Atom feeds
  • Bypasses compression on admin/dashboard pages to free up resources for other tools/plugins
  • Compresses themes that don’t make use of a header.php file (previously did not)
  • Removes any empty attributes using single-quote encapsulation (previously supported only double-quotes)
  • Removes excess spacing within opening and closing tags (previously supported only self-closing tags)
  • Converts new lines to spaces so that rendered whitespace is preserved
  • Simplified compression statistics comment
  • PHP errors hidden if/when plugin file is accessed directly
  • Speed optimizations

0.4

  • Removes empty attributes except action, alt, content, src

0.3

  • Comments in <textarea> are no longer removed. Browsers seem to display such text
  • Removes excess spacing within self-closing tags
  • Speed optimizations

0.2

  • Fixed compression override

0.1

  • Initial release