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 »

  • This plugin is such a fantastic example of good clean coding. It’s fine that you are a “nerd” about some things :) It’s totally worth it.

    If you could add combine CSS and combine JS functionality, ideally placing the joint JS at the end of the document just before the closing BODY tag, that’ll make this perfect.

    Thanks!

  • Hi. I am not sure what this plugin does. I got it working, enabled it. But all it does is minifies the HTML.

    Isn’t it also supposed to:

    1. Combine all my CSS + JS files into one each
    2. And minify their internal contents too?

    Thanks.

  • got a problem when using the minify_skip tags on Google Adsense code handled by Author Advertising plugin. When 2 or more Google Adsense code with different ad sizes are on the same page with minify_skip tags, the second code gets the same ad size as the first.

  • I tried it in my blog and suddenly all of pages turn out blank. I didn’t activate the debug level to show up when errors happen and this make me unable to know what went wrong. But I can guess that the theme may cause the trouble because when I change it into default wordpress theme (Twentyten), Everything work just fine. For now on, I’ll just using the Super Cache and trying to minify everything manually (already done it in CSS and some parts of the theme).
    ^__^
    I love this plugin and even it didn’t work in my theme, I still love it.
    NISYA (Linatul Ainisiyah)

  • […] tab of the WP Super Cache plugin, there are a list of recommended plusings.  I chose to add the WPSCMin and the CDN Sync Tool […]

  • after i change the themes to the premium visitor dropped by 60% if this plugin can help, hopefully

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

    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/.
    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.

    but don’t get
    Log into your site, go to the WP Super Cache config page, and scroll to the bottom. Enable HTML Minify, and you’re done!
    where do i get the enable function.??
    btw use WPSC ver 1.1

  • […] WPSCMin: HTML Minify plugin for WordPress and WP Super Cache | lyncd.com. This entry was posted in WordPress Plugins by admin. Bookmark the permalink. […]

  • thank you very much …

  • I simply get just a white page when I enable the plug in :(

    • i have the same problem, with this plugin disables super cache works else generates empty 0 byte files.

      did u find any solution?

  • very cool sharing, i m going to try :)

  • […] WPSCMin 一个可以通过移除空白部分和不必要的字符来缩小缓存页面大小的 Super Cache 插件。 // 推荐: 标签: WordPress 插件 […]

  • […] WPSCMin 一个可以通过移除空白部分和不必要的字符来缩小缓存页面大小的 Super Cache 插件。 标签: WordPress 插件 […]

  • Plugin to a plugin… funny idea :) I’ll check it out when I get to my pc where I’ve ftp account configured. Bad that I can’t just upload this plugin via wordpress’ cms panel.

  • using super cache v1.2 and WPSCMin-0.5 with minify v2.1.5

    when i Test Cache
    if WPSCMin is enabled super cache do not cache & generates an error of time difference between the 1.htm & 2.htm, when disable WPSCMin super cache works.

    Also both the 1.htm & 2.htm files generated by Test Cache are of 0 bytes.

    what wrong?

  • […] WPSCMin 一个可以通过移除空白部分和不必要的字符来缩小缓存页面大小的 Super Cache 插件。 […]

  • […] es muss nur richtig gemacht werden.Ladet als erstes die entsprechende WPSCMin Erweiterung von der Webseite und kopiert die enthaltene “WPSCMin.php” in folgendes Verzeichnis […]

  • Hi if you are finding this is not working or producing blank white pages or a server 500 error it is most probably because of two things:

    1. You may not have read the instructions fully and downloaded both the plugin AND minify
    2. It is not clear in the instructions but you have to move the ‘min’ folder from the current release minify-2.1.5.zip to the same path as your /wp-super-cache/plugins directory. If you just unzip minify it extracts a folder called minify-version-number, inside that folder is another one called ‘min’. You got to mv this to the plugins folder, so up a level for it to work! Instructions could be clearer I just figured it out. HTH anyone having issues.

  • Thanks alot. Great Plugin

  • nice plugin.. i will compare super cache with w3 total cache.. thanks