lyncd

WPSCMin: HTML Minify plugin for WordPress and WP Super Cache

WPSCMin is a plugin to a plugin: A plugin for the static-caching WordPress plugin WP Super Cache, it uses Minify to strip whitespace and comments from your web pages. Your super-fast static-cached pages will shrink a further 5-20% in size.

If you used a previous version of my code, the good news is that it’s now a fully fledged plugin to WP Super Cache, so it’s an easy install (no more patches! no more breakage when Super Cache changes!).

What it does
  1. Minifies HTML pages that WP Super Cache saves to its static caches (including inline JavaScript and CSS style declarations). In my tests, uncompressed HTML pages shrink a further 10-20%, while gzipped pages shrink a further 3-10%.
  2. Adds a handy “on/off” control to the Super Cache options screen in the WordPress backend. So, you can turn it off for debugging, or to read your pretty indented source code.
What it doesn’t do
  1. Minify standalone JavaScript and CSS files. I prefer to do these as part of a build process, so they’re both small and static. (I’m a nerd about this: My build scripts even use advdef/7-Zip/zopfli to squeeze an extra 10% over gzip -9.)
  2. Minify dynamic pages. The CPU cost of minifying a dynamic page greatly outweighs the bandwidth savings — minifying HTML only makes sense in concert with a static-caching solution like Super Cache, or if you’re using a caching front-end proxy like Varnish or Squid. The whole point of my plugin is that it doesn’t waste resources minifying dynamic pages, only those cached by Super Cache.

If that didn’t make sense, or for more discussion, feel free to take a look at my original release post, where I get into greater detail.

Installation and upgrade

Last update: Updated to version 0.7 on 9/28/2015. Tested with Minify 2.2.0.

Requirements: PHP5. WP Super Cache 0.9.9.6+. (See advanced usage below to use with older versions of Super Cache.)

  1. Download the current version and unzip. Move WPSCMin.php into the plugins subdirectory of WP Super Cache. If yours is a standard WordPress install, this will be wp-content/plugins/wp-super-cache/plugins/.
  2. Download the current version of Minify and unzip. Move the min directory into the plugins subdirectory of WP Super Cache, right next to WPSCMin.php.
  3. Log into your site, go to the WP Super Cache config page, and scroll to the bottom. Enable HTML Minify, and you’re done!

WPSCMin configuration screenshot
Note to upgraders: If you’re upgrading from version 0.4, you only need to replace WPSCMin.php with the new version of the file (and that’s it!). If you’re upgrading from version 0.3 or older (the ones with all the patches), be sure to replace your patched Super Cache files with fresh ones, and notice in the instructions above that the location of WPSCMin.php and min changed.

Advanced usage

Version 0.5 added several optional features for advanced users. Read on to learn how to:

Mark sections of HTML so that they will not be minified

If there are sections of your pages that you don’t want to minify (for instance, certain HTML comments like AdSense slot IDs), you can tell WPSCMin to skip them. Just surround whatever HTML code you don’t want minified with <!--[minify_skip]--> and <!--[/minify_skip]-->. (By the way, these “minify_skip” tags are themselves stripped when the page is minified.)

Install Minify in an alternate location or point to an existing install of Minify

Generally, having more than one copy of the Minify PHP files on your system shouldn’t cause a problem, because WPSCMin checks to see whether Minify is loaded before including it again. However, if you want to point to a Minify min directory somewhere else on your filesystem, you can now do that.

Edit your WP Super Cache config file wp-cache-config.php and create a new line that sets the variable $cache_minify_path to the full filesystem path of the directory containing the Minify min directory. It should look something like this:

// i.e. if Minify were in /some/path/to/a/dir/min
$cache_minify_path = '/some/path/to/a/dir';
Use with an older (0.9.9.5 or earlier) version of WP Super Cache

To use with Super Cache versions 0.9.9.3-0.9.9.5, there’s some compatibility code you can enable by editing WPSCMin.php. There are three commented-out lines that you will need to enable and then two lines immediately following that you must delete or comment out. These code sections are well-marked and should be easy to spot if you open WPSCMin.php in your favorite editor and search for the text “For versions of WP Super Cache 0.9.9.5 and earlier”.

For even older versions (and this is really unsupported) of Super Cache, the above compatibility fix may work fine (it’s just untested prior to 0.9.9.3). If not, well, you should really upgrade WP Super Cache or just not worry about minifying your HTML! But, if you still aren’t deterred, take a look at the changelog and see which of the 2008-2009 releases (which require patching Super Cache) may be compatible with your version of Super Cache. Then go to the old files and installation instructions.

Comments, bug reports

Please add them here!

62 comments »

Add a comment

You can also log in (or register) for easier commenting on lyncd.

Lyncd is an evolving group blog-in-progress. Weʼll be designing the site, adding users and content, and developing a hifalutin site focus as we go. For now, just think of our site mantra as “minimalism.” :)