A question that has come up a couple of times already is how Autoptimize and it’s cache work. So let’s do some copy/pasting of what I replied earlier on the wordpress.org support forum;
- AO intercepts the HTML created by WordPress for a request (using the output buffer)
- all references to JS (and CSS) are extracted from the HTML
- all original references to JS (and CSS) are removed from the HTML (the code in the original files is left as is, AO never changes those files)
- all JS (and CSS) is aggregated (JS in one string, CSS in as many strings as there were media types)
- the md5-hash (mathematical/ cryptographic function that generates a quasi-unique string based on another string) of the aggregated JS (and CSS) is calculated
- using the md5 AO checks if a cached file with that md5 exists and if so continues to step 8
- if no cached file is found, the JS (and CSS) is minified and cached in a new file, with the md5 as part of the filename
- the links to the autoptimized JS (and CSS) file in cache are injected in the HTML
- the HTML is minified (but not cached in Autoptimize)
- the HTML is returned to WordPress (where it can be cached by a page cache and sent to the visitor)
This is especially interesting if you want to understand why the cache size can “explode”; if in step 4 the code is even a bit different from previous requests, the md5-hash in step 5 will be different so the file will not be found in cache (step 6) and the code will be re-minified (which is relatively expensive) and cached (step 7).
And that, my friends, is how Autoptimize works.
do i need to delete the cache where it shows the cache info with size and files in my wordpress dashboard?
if yes, how often?
it all depends on how fast cache-size grows (if fast, see my canary in the coalmine post) and how much disk space you can spare. my cache is at 1.89MB now, after one month, so no need to clear … ๐
Cache warning happens at least once per week for me in case I do not manually erase it. What am I doing wrong? The site has 100+ pages plus 400+ posts. Is Autoptimize suitable for me at all or do I need to look for something different?
You’ll have to check (amend) Autoptimize’s configuration Toni; I bet you are “also aggregating inline JS” which is the cause of 99%ยจof all AO cache-troubles (more info in the FAQ).
your diagnosis was correct! I watched it for a few days and the cache is at 3 MB now. Thank you, Frank.
Can I use Autoptimize at the same time with w3total cache?
Yes, if you disable the minification features in W3TC ๐