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
- 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%.
- 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
- 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
.) - 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.)
- Download the current version and unzip. Move
WPSCMin.php
into theplugins
subdirectory of WP Super Cache. If yours is a standard WordPress install, this will bewp-content/plugins/wp-super-cache/plugins/
. - Download the current version of Minify and unzip. Move the
min
directory into theplugins
subdirectory of WP Super Cache, right next toWPSCMin.php
. - Log into your site, go to the WP Super Cache config page, and scroll to the bottom. Enable HTML Minify, and you’re done!
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!
Phoenix
March 29, 2012, 9:56 am
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!
Phoenix
April 3, 2012, 2:06 am
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.
marhgil
May 26, 2012, 2:56 am
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.
Skripsi
June 13, 2012, 11:20 am
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)
Ping from The Need For Speed | Dave Wooding
June 16, 2012, 11:08 am
[…] 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 […]
lekko
June 16, 2012, 10:26 pm
after i change the themes to the premium visitor dropped by 60% if this plugin can help, hopefully
Kletskater
June 17, 2012, 12:51 pm
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
Ping from WPSCMin: HTML Minify plugin for WordPress and WP Super Cache | lyncd.com | Web Development Notes
July 18, 2012, 5:50 am
[…] WPSCMin: HTML Minify plugin for WordPress and WP Super Cache | lyncd.com. This entry was posted in WordPress Plugins by admin. Bookmark the permalink. […]
web design
Aug. 25, 2012, 1:21 am
thank you very much …
Yves
Oct. 7, 2012, 7:36 am
I simply get just a white page when I enable the plug in :(
sam
Dec. 15, 2012, 4:42 am
i have the same problem, with this plugin disables super cache works else generates empty 0 byte files.
did u find any solution?
Cricketbook
Oct. 27, 2012, 10:22 am
very cool sharing, i m going to try :)
Ping from WordPress缓存插件:WPSCMin
Nov. 19, 2012, 2:19 pm
[…] WPSCMin 一个可以通过移除空白部分和不必要的字符来缩小缓存页面大小的 Super Cache 插件。 // 推荐: 标签: WordPress 插件 […]
Ping from WordPress缓存插件:WPSCMin
Nov. 19, 2012, 3:18 pm
[…] WPSCMin 一个可以通过移除空白部分和不必要的字符来缩小缓存页面大小的 Super Cache 插件。 标签: WordPress 插件 […]
Kamil
Nov. 24, 2012, 5:06 am
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.
sam
Dec. 15, 2012, 4:39 am
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?
Ping from WordPress 缓存插件:WPSCMin 一卷纸和书
Dec. 18, 2012, 4:46 am
[…] WPSCMin 一个可以通过移除空白部分和不必要的字符来缩小缓存页面大小的 Super Cache 插件。 […]
Ping from WordPress beschleunigen mit WP-Super-Cache und HTML Minify (WPSCMin) › Webdesign-Podcast
Jan. 4, 2013, 10:55 am
[…] 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 […]
Chris G
Jan. 14, 2013, 12:12 pm
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.
Kashan Ahmer
Jan. 18, 2013, 8:56 am
Thanks alot. Great Plugin
www.bebetterself.com
Jan. 19, 2013, 4:46 am
nice plugin.. i will compare super cache with w3 total cache.. thanks