Plugin Author: Frank Goossens (futtta)
WordPress profile: Frank Goossens (futtta)
Last updated: December 4, 2018 (2 months ago)
Tested up to (WP version): WP 5.0.3
Rating: 5 (out of 5)
If you consider performance important, you really should use one of the many caching plugins to do page caching. Some good candidates to complement Autoptimize that way are e.g. WP Super Cache, HyperCache, Comet Cache or KeyCDN’s Cache Enabler.
We provide great Autoptimize Pro Support and Web Performance Optimization services, check out our offering on https://autoptimize.com/!
(Speed-surfing image under creative commons by LL Twistiti)
What does the plugin do to help speed up my site?
It concatenates all scripts and styles, minifies and compresses them, adds expires headers, caches them, and moves styles to the page head, and scripts (optionally) to the footer. It also minifies the HTML code itself, making your page really lightweight.
But I’m on HTTP/2, so I don’t need Autoptimize?
HTTP/2 is a great step forward for sure, reducing the impact of multiple requests from the same server significantly by using the same connection to perform several concurrent requests. That being said, concatenation of CSS/ JS can still make a lot of sense, as described in this css-tricks.com article and this blogpost from one of the Ebay engineers. The conclusion; configure, test, reconfigure, retest, tweak and look what works best in your context. Maybe it’s just HTTP/2, maybe it’s HTTP/2 + aggregation and minification, maybe it’s HTTP/2 + minification (which AO can do as well, simply untick the “aggregate JS-files” and/ or “aggregate CSS-files” options).
Will this work with my blog?
Although Autoptimize comes without any warranties, it will in general work flawlessly if you configure it correctly. See “Troubleshooting” below for info on how to configure in case of problems.
Why is jquery.js not optimized
Starting from AO 2.1 WordPress core’s jquery.js is not optimized for the simple reason a lot of popular plugins inject inline JS that is not aggregated either (due to possible cache size issues with unique code in inline JS) which relies on jquery being available, so excluding jquery.js ensures that most sites will work out of the box. If you want optimize jquery as well, you can remove it from the JS optimization exclusion-list (you might have to enable “also aggregate inline JS” as well or switch to “force JS in head”).
Why is Autoptimized JS render blocking?
If not “forced in head”, Autoptimized JS is not render blocking as it has the “defer” flag added. It is however possible another plugin removes the “defer”-flag. Speed Booster Pack was reported doing this, but the behavior has not been confirmed yet.
Why is the autoptimized CSS still called out as render blocking?
With the default Autoptimize configuration the CSS is linked in the head, which is a safe default but has Google PageSpeed Insights complaining. You can look into “inline all CSS” (easy) or “inline and defer CSS” (better) which are explained in this FAQ as well.
What is the use of “inline and defer CSS”?
CSS in general should go in the head of the document. Recently a.o. Google started promoting deferring non-essential CSS, while inlining those styles needed to build the page above the fold. This is especially important to render pages as quickly as possible on mobile devices. As from Autoptimize 1.9.0 this is easy; select “inline and defer CSS”, paste the block of “above the fold CSS” in the input field (text area) and you’re good to go!
But how can one find out what the “above the fold CSS” is?
There’s no easy solution for that as “above the fold” depends on where the fold is, which in turn depends on screensize. There are some tools available however, which try to identify just what is “above the fold”. This list of tools is a great starting point. The Sitelocity critical CSS generator and Jonas Ohlsson’s criticalpathcssgenerator are nice basic solutions and http://criticalcss.com/ is a premium solution by the same Jonas Ohlsson. Alternatively this bookmarklet (Chrome-only) can be helpful as well.
Or should you inline all CSS?
The short answer: probably not.
Back in the days CSS optimization was easy; put all CSS in your head, aggregating everything in one CSS-file per media-type and you were good to go. But ever since Google included mobile in PageSpeed Insights and started complaining about render blocking CSS, things got messy (see “deferring CSS” elsewhere in this FAQ). One of the solutions is inlining all your CSS, which as of Autoptimize 1.8.0 is supported.
Inlining all CSS has one clear advantage (better PageSpeed score) and one big disadvantage; your base HTML-page gets significantly bigger and if the amount of CSS is big, Pagespeed Insights will complain of “roundtrip times”. Also when looking at a test that includes multiple requests (let’s say 5 pages), performance will be worse, as the CSS-payload is sent over again and again whereas normally the separate CSS-files would not need to be sent any more as they would be in cache.
So the choice should be based on your answer to some site-specific questions; how much CSS do you have? How many pages per visit do your visitors request? If you have a lot of CSS or a high number of pages/ visit, it’s probably not a good idea to inline all CSS.
You can find more information on this topic in this blog post.
My cache is getting huge, doesn’t Autoptimize purge the cache?
Autoptimize does not have its proper cache purging mechanism, as this could remove optimized CSS/JS which is still referred to in other caches, which would break your site. Moreover a fast growing cache is an indication of other problems you should avoid.
Instead you can keep the cache size at an acceptable level by either:
- disactivating the “aggregate inline JS” and/ or “aggregate inline CSS” options
- excluding JS-variables (or sometimes CSS-selectors) that change on a per page (or per pageload) basis. You can read how you can do that in this blogpost.
Despite above objections, there are 3rd party solutions to automatically purge the AO cache, e.g. using this code or this plugin, but for reasons above these are to be used only if you really know what you’re doing.
“Clear cache” doesn’t seem to work?
When clicking the “Delete Cache” link in the Autoptimize dropdown in the admin toolbar, you might to get a “Your cache might not have been purged successfully”. In that case go to Autoptimizes setting page and click the “Save changes & clear cache”-button.
Moreover don’t worry if your cache never is down to 0 files/ 0KB, as Autoptimize (as from version 2.2) will automatically preload the cache immediately after it has been cleared to speed further minification significantly up.
Can I still use Cloudflare’s Rocket Loader?
At the moment (June 2017) it seems RocketLoader might break AO’s “inline & defer CSS”, which is based on Filamentgroup’s loadCSS, resulting in the deferred CSS not loading.
I tried Autoptimize but my Google Pagespeed Scored barely improved
Autoptimize is not a simple “fix my Pagespeed-problems” plugin; it “only” aggregates & minifies (local) JS & CSS and allows for some nice extra’s as removing Google Fonts and deferring the loading of the CSS. As such Autoptimize will allow you to improve your performance (load time measured in seconds) and will probably also help you tackle some specific Pagespeed warnings. If you want to improve further, you will probably also have to look into e.g. page caching, image optimization and your webserver configuration, which will improve real performance (again, load time as measured by e.g. https://webpagetest.org) and your “performance best practise” pagespeed ratings.
What can I do with the API?
A whole lot; there are filters you can use to conditionally disable Autoptimize per request, to change the CSS- and JS-excludes, to change the limit for CSS background-images to be inlined in the CSS, to define what JS-files are moved behind the aggregated one, to change the defer-attribute on the aggregated JS script-tag, … There are examples for some filters in autoptimize_helper.php_example and in this FAQ.
How does CDN work?
Starting from version 1.7.0, CDN is activated upon entering the CDN blog root directory (e.g. http://cdn.example.net/wordpress/). If that URL is present, it will used for all Autoptimize-generated files (i.e. aggregated CSS and JS), including background-images in the CSS (when not using data-uri’s).
If you want your uploaded images to be on the CDN as well, you can change the upload_url_path in your WordPress configuration (/wp-admin/options.php) to the target CDN upload directory (e.g. http://cdn.example.net/wordpress/wp-content/uploads/). Do take into consideration this only works for images uploaded from that point onwards, not for images that already were uploaded. Thanks to BeautyPirate for the tip!
Why aren’t my fonts put on the CDN as well?
Autoptimize supports this, but it is not enabled by default because non-local fonts might require some extra configuration. But if you have your cross-origin request policy in order, you can tell Autoptimize to put your fonts on the CDN by hooking into the API, setting
true this way;
I’m using Cloudflare, what should I enter as CDN root directory
Nothing, when on Cloudflare your autoptimized CSS/ JS is on the Cloudflare’s CDN automatically.
How can I force the aggregated files to be static CSS or JS instead of PHP?
If your webserver is properly configured to handle compression (gzip or deflate) and cache expiry (expires and cache-control with sufficient cacheability), you don’t need Autoptimize to handle that for you. In that case you can check the “Save aggregated script/css as static files?”-option, which will force Autoptimize to save the aggregated files as .css and .js-files (meaning no PHP is needed to serve these files). This setting is default as of Autoptimize 1.8.
How does “exclude from optimizing” work?
Both CSS and JS optimization can skip code from being aggregated and minimized by adding “identifiers” to the comma-separated exclusion list. The exact identifier string to use can be determined this way:
- if you want to exclude a specific file, e.g. wp-content/plugins/funkyplugin/css/style.css, you could simply exclude “funkyplugin/css/style.css”
- if you want to exclude all files of a specific plugin, e.g. wp-content/plugins/funkyplugin/js/*, you can exclude for example “funkyplugin/js/” or “plugins/funkyplugin”
- if you want to exclude inline code, you’ll have to find a specific, unique string in that block of code and add that to the exclusion list. Example: to exclude
<script>funky_data='Won't you take me to, Funky Town'</script>, the identifier is “funky_data”.
Configuring & Troubleshooting Autoptimize
If your blog doesn’t function normally after having turned on Autoptimize, here are some pointers to identify & solve such issues using “advanced settings”:
- If all works but you notice your blog is slower, ensure you have a page caching plugin installed (WP Super Cache or similar) and check the info on cache size (the solution for that problem also impacts performance for uncached pages) in this FAQ as well.
- In case your blog looks weird, i.e. when the layout gets messed up, there is problem with CSS optimization. In this case you can turn on the option “Look for styles on just head?” and see if that solves the problem. You can also force CSS not to be aggregated by wrapping it in noptimize-tags in your theme or widget or by adding filename (for external stylesheets) or string (for inline styles) to the exclude-list.
- If your theme or plugin require jQuery, you can try either forcing all in head and/ or excluding jquery.js (and jQuery-plugins if needed).
- If you can’t get either CSS or JS optimization working, you can off course always continue using the other two optimization-techniques.
- If you tried the troubleshooting tips above and you still can’t get CSS and JS working at all, you can ask for support on the WordPress Autoptimize support forum. See below for a description of what information you should provide in your “trouble ticket”
Help, I have a blank page or an internal server error after enabling Autoptimize!!
Make sure you’re not running other HTML, CSS or JS minification plugins (BWP minify, WP minify, …) simultaneously with Autoptimize or disable that functionality your page caching plugin (W3 Total Cache, WP Fastest Cache, …). Try enabling only CSS or only JS optimization to see which one causes the server error and follow the generic troubleshooting steps to find a workaround.
But I still have blank autoptimized CSS or JS-files!
If you are running Apache, the htaccess file written by Autoptimize can in some cases conflict with the AllowOverrides settings of your Apache configuration (as is the case with the default configuration of some Ubuntu installations), which results in “internal server errors” on the autoptimize CSS- and JS-files. This can be solved by setting AllowOverrides to All.
I get no error, but my pages are not optimized at all?
Autoptimize does a number of checks before actually optimizing. When one of the following is true, your pages won’t be optimized:
- when in the customizer
- if there is no opening
- if there is
<xsl:stylesheetin the response (indicating the output is not HTML but XML)
- if there is
<html ampin the response (as AMP-pages are optimized already)
- if the output is an RSS-feed (is_feed() function)
- if the output is a WordPress administration page (is_admin() function)
- if the page is requested with ?ao_noptimize=1 appended to the URL
- if code hooks into Autoptimize to disable optimization (see topic on Visual Composer)
- if other plugins use the output buffer in an incompatible manner (disable other plugins selectively to identify the culprit)
Visual Composer, Beaver Builder and similar page builder solutions are broken!!
Disable the option to have Autoptimize active for logged on users and go crazy dragging and dropping 😉
Help, my shop checkout/ payment don’t work!!
Disable the option to optimize cart/ checkout pages (works for WooCommerce, Easy Digital Downloads and WP eCommerce).
Revolution Slider is broken!
js/jquery/jquery.js is in the comma-separated list of JS optimization exclusions (this is excluded in the default configuration).
I’m getting “jQuery is not defined” errors
js/jquery/jquery.js to the comma-separated list of JS optimization exclusions.
I use NextGen Galleries and a lot of JS is not aggregated/ minified?
add_filter( 'run_ngg_resource_manager', '__return_false' ); or you can tell Autoptimize to initialize earlier, by adding this to your wp-config.php:
What is noptimize?
Starting with version 1.6.6 Autoptimize excludes everything inside noptimize tags, e.g.:
<!--noptimize--><script>alert(‘this will not get autoptimized’);</script><!--/noptimize-->
You can do this in your page/ post content, in widgets and in your theme files (consider creating a child theme to avoid your work being overwritten by theme updates).
Can I change the directory & filename of cached autoptimize files?
Yes, if you want to serve files from e.g. /wp-content/resources/aggregated_12345.css instead of the default /wp-content/cache/autoptimize/autoptimize_12345.css, then add this to wp-config.php:
Can the generated JS/ CSS be pre-gzipped?
Yes, but this is off by default. You can enable this by passing ´true´ to ´autoptimize_filter_cache_create_static_gzip´. You’ll obviously still have to configure your webserver to use these files instead of the non-gzipped ones to avoid the overhead of on-the-fly compression.
What does “remove emojis” do?
This new option in Autoptimize 2.3 removes the inline CSS, inline JS and linked JS-file added by WordPress core. As such is can have a small positive impact on your site’s performance.
Is “remove query strings” useful?
Although some online performance assessement tools will single out “query strings for static files” as an issue for performance, in general the impact of these is almost non-existant. As such Autoptimize, since version 2.3, allows you to have the query string (or more precisely the “ver”-parameter) removed, but ticking “remove query strings from static resources” will have little or no impact of on your site’s performance as measured in (milli-)seconds.
(How) should I optimize Google Fonts?
Should I use “preconnect”
Preconnect is a somewhat advanced feature to instruct browsers (if they support it) to make a connection to specific domains even if the connection is not immediately needed. This can be used e.g. to lessen the impact of 3rd party resources on HTTPS (as DNS-request, TCP-connection and SSL/TLS negotiation are executed early). Use with care, as preconnecting to too many domains can be counter-productive.
When can(‘t) I async JS?
How does image optimization work?
When image optimization is on, Autoptimize will look for png, gif, jpeg (.jpg) files in image tags and in your CSS files that are loaded from your own domain and change the src (source) to the ShortPixel CDN for those.
Where can I get more info on image optimization?
Have a look at Shortpixel’s FAQ.
Can I disable the minification of excluded JS/ CSS?
As from AO 2.4 excluded JS/ CSS are minified if the (filename indicates the) file is not minified yet. You can disable this with these filters;
Can I disable AO listening to page cache purges?
As from AO 2.4 AO “listens” to page cache purges to clear its own cache. You can disable this behavior with this filter;
Why can’t I upgrade from 2.3.4 to 2.4.0 (or higher)?
Main reason (apart from occasional hickups that seem to be inherent to plugin upgrades) is that AO 2.4 requires you to be running PHP 5.3 or higher. And let’s face it; you should actually be running PHP 7.x if you value performance (and security and support), no?
Some of the non-ASCII characters get lost after optimization
By default AO uses non multibyte-safe string methods, but if your PHP has the mbstring extension you can enable multibyte-safe string functions with this filter;
The Shortpixel image optimizing notice cannot be dismissed?
In some rare cases the logic to dismiss the notice does not work due to the transient (WordPress cache) not keeping the dismissed state. If this happens you can use this code snippet to make the notice go away;
add_filter( 'autoptimize_filter_main_imgopt_plug_notice', '__return_empty_string' );
Where can I get help?
You can get help on the wordpress.org support forum. If you are 100% sure this your problem cannot be solved using Autoptimize configuration and that you in fact discovered a bug in the code, you can create an issue on GitHub. If you’re looking for premium support, check out our Autoptimize Pro Support and Web Performance Optimization services.
I want out, how should I remove Autoptimize?
- Disable the plugin (this will remove options and cache)
- Remove the plugin
- Clear any cache that might still have pages which reference Autoptimized CSS/JS (e.g. of a page caching plugin such as WP Super Cache)
How can I help/ contribute?
Just fork Autoptimize on Github and code away!
Latest Change log entry:
- bugfix: safer way of removing extra cronjobs
image optimization, minify, Optimize, pagespeed, performance
+ Jason's Comments
This plugin catches the output buffer to collect scripts. After some rendering problems, I now recommend a Better WordPress Minify plugin which collects the scripts from WordPress’s enqueueing system rather than the output buffer.
Website Optimization and Maintenance
There are a few ways to optimize and speed up your website for viewers and search engines: database clean up, image optimization, page / script compression, CPU / server load optimization, server file caching and utilize browser caching.