Autoptimize is a WordPress plugin for improving your website performance. It scans the output of your WordPress website to reduce the size and number of files that web browsers download from your website. Here’s a quick rundown of what it can do:
- strip comments and redundant whitespace from the HTML
- strip comments and whitespace from CSS stylesheets
- concatenate scripts from your website into a single downloadable file
- concatenate stylesheets from your website into a single downloadable file
- move in-line scripts and stylesheets into the concatenated files
Each of those actions is configurable too, which is great. In fact, it’s absolutely necessary, because each of those functions can break your website in fun and fascinating ways! Some scripts and stylesheets just don’t want to play ball, so Autoptimize isn’t something you can just install and turn on, then head to the pub for a congratulatory cider. You need to test everything!
Three things in particular can bring Autoptimized websites unstuck:
- rearranging order-sensitive scripts or stylesheets into the wrong order
- including unique resources in concatenated files, forcing a unique concatenated file for every page/post
- including big scripts or stylesheets used on every page/post in concatenated files
The first mistake can break your website. The second one probably won’t break it, but it’ll mean that you won’t benefit from web browser caching of your concatenated files. The third one means that each of your concatenated files includes a pile of stuff that the browser has already loaded, and could have cached.
- push jQuery off to Google’s CDN with Use Google Libraries — that will reduce the size of each .js cached file, because jQuery is usually loaded on every page
- look at the cache folder, see if there are lots of .js files, which indicates too much uniqueness in cached script — probably an embedded script block that is unique to each page/post
- test every page — some scripts need special handling and may break with default settings
Once you’ve identified your problems, you can add exceptions to the Autoptimize settings:
Here’s a list I’ve compiled for various common plugins
- Disqus — disqus_config,disqusConfig,disqusShortname
- Easy Digital Downloads — edd_scripts,edd_global_vars
- Flexible Map — flxmap
- Gist — gist.github.com
- NextCellent Gallery with Shutter Reloaded — ngg,shutter,jquery.cycle,googleapis
- ReCAPTCHA — recaptcha
- Use Google Libraries — jQuery.noConflict
- general catch-all for many plugins: CDATA
Why you shouldn’t use Autoptimize
For shared hosting websites, I like Autoptimize because it’s easy to configure and does a great job. There are other options, however; just look at the list of minify plugins on WordPress.org! Some page caching plugins also offer minification / concatenation, e.g. W3 Total Cache. For me, Autoptimize + WP Super Cache and some custom .htaccess rules gets me where I want to go, simply and quickly.
If you have control of your website configuration, you’re better off using the PageSpeed module. It can do what Autoptimize does, and more — but it does it at the web server level, outside of WordPress. It has a pile of configuration options so you can really fine-tune your website.
If you have CloudFlare, you can turn on some minification / concatenation features of its service with the Rocket Loader and let CloudFlare take the load for you. It can be harder to control, however, because opting a script out of Rocket Loader requires changing script tags.
Autoptimize can really help reduce the size and number of resources your website pages load, leading to a faster website. Just make sure you test everything carefully, check that you don’t have lots of similar concatenated files in the cache, and use judiciously where it can help your website, not hurt it. Otherwise you might find, as Eric Sevareid once said:
The chief cause of problems is solutions