Hi Michael,
The short answer is that you need to test how is the cache growing and where exactly are the differences ??
Here’s some more info:
a) FVM, primarily creates a unique hash name based on appending the “handles” names of the enqueued css/js files. Handles are defined when you enqueue your css and js files.
https://developer.www.ads-software.com/reference/functions/wp_enqueue_script/
b) WordPress uses dependencies, meaning that you can append inline data for both js and css files using wp_add_inline_script
and wp_add_inline_style
https://developer.www.ads-software.com/reference/functions/wp_add_inline_script/
https://codex.www.ads-software.com/Function_Reference/wp_add_inline_style
If there is any, FVM will minify and then create another hash out of that “unique” minified code, append it to the handles names and then hash the final, unique result again.
c) If on any page, post, category, etc… any of the handles or inline css/js change, it will obviously have a new unique hash, thus creating a new cache file.
d) FVM copies all css and js files it sees and first minifies them independently to an intermediate cache on the fvm/tmp directory. While checking for c)
will collect a list of files (and inlined code) to be merged, and reuse any of the previously minified, independent files… so it minfies once and reuses those copies to create merged files.
—
To evaluate you need to verify if each page is actually really creating new files per unique url or not, or if it’s just the name changing, or if it seems that there is unique css code on each page but in fact, there is a large number of slightly different number of unique inlined css files that sometimes, repeat on other urls.
For example, let’s say that the inline css for a user profile that has filled 10 fields, has 10 classes inlined.
Another user has filled 12 fields on his profile and he now has 12 classes inlined on his profile url.
You need to check if all users that have filled the same exact amount and type of data, all share the same css or if, regardless of them being almost an exact copy of each other (except for the text or image), they still trigger a new css file, or css handle name.
Create 2 profiles which are identical to each other, except on the information provided. Disable FVM and do a diff check on the saved html for any css or js name or content changes.
If those 2 similar profiles share the same exact handle names and inline code, FVM will only generate 1 file for all. If it generates 2, something is changing (enable the debug mode on FVM and check your html for comments of what is being processed).
If you only have 1 file generated by FVM, then that should be correct.
It doesn’t matter if other profiles generate yet another css file, because now you know that similar profiles will share their css.
If the data is similar, but the name changes… something is horribly wrong with whatever is generating that. It may be better to simply manually dequeue any generated css/js that is causing that, dump all code into a static file and enqueue it as a static file.
https://developer.www.ads-software.com/themes/basics/including-css-javascript/
—
When you inline all css, a couple of things happen after my updates.
It now skips merging the css, although it still copies and minifies each css and it’s inlined data to a temporary directory, but this time instead of merging it first, it outputs the code directly into the theme.
That means, if one of your css files change, or if one of it’s inlined code (children) changes, a new minified cache will be generated for that file only, instead of a new larger cache file every time.
The cache will still grow, but at a slower rate… so your goal, is to make sure the css that is changing stays static and doesn’t change.
You have to check where that different css code is coming from and instead of loading bits and pieces, remove that logic and have it all in one enqueued file instead.
If each user is allowed to style it’s profile page, then you have to recode that functionality to output the personalized css code, not inlined as a child of the theme/plugin, but rather as another file (which could be a php file with some unique query string and some logic).
You would then exclude that file from FVM so the rest of the files won’t change, and FVM stop detecting that change.
Nevertheless, let me say that having unique cache on every profile is not good practice. You should have all possible css code in one css file and that’s it.
—
In regard of inlining large css files, it usually doesn’t matter much because of gzip/brotli compression. Even if you inline 1 MB of CSS, that’s still probably going to be less than 256KB compressed (maybe).
As a rule of thumb, I always inline css on the footer, then evaluate it the header can be inlined or not.
How you decide if you should inline it or not… is with google pagespeed insights.
You setup a cache plugin and try with and without inline, repeating the test a few times to make sure the html has been cached.
If you have too much css in the header, pagespeed will start complaining about the time to first byte (it seems that someone at google doesn’t really understand what ttfb is… they probably meant to call it, prioritize visible content instead, but whatever).
When you don’t inline, it will complain about the render blocking css instead.
That’s why you look for the score before and after to decide which one to use.
There will be a level where inlining will give you better score, but when it’s large enough, having it render blocking will be better.
—
In regard of EFS… if I’m not mistaken, FVM works separately on each server if you want. You could define a “local” cache directory on FVM settings and have each server generate it’s files locally, per server.
It gets the “latest version number” from the database, and the unique factor from the handles and inlined css/js code. If you use a local path instead of EFS, it will always check if the file exist or not, and if not it will create it again on each server.
That should be fine, because the hash should be the same on all servers… and the only drawback, is that whenever you hit a server without a fvm cache, it will regenerate it again.
Page cache… I’m not sure how you are using it, but if each server has its own cache, it will work.
If instead, you use elastic to cache the html on memcached, then the referenced js/css file may not be there because there was no php request to trigger the regeneration.
In that case, you could instead use Varnish and use it as a reverse proxy to the load balancer… it would hit whatever server, have FVM generate the file and then cache it on Varnish directly. Then it wouldn’t matter if other servers have the cache file or not, because when the next varnish cache is invalid, it would trigger any server php, which would then regenerate the file and repeat the process.
—
Finally, if EFS is too expensive, you could create an s3 bucket and use it as a mounting point for the uploads/fvm
directory (do not do this for the php files).
https://cloud.netapp.com/blog/amazon-s3-as-a-file-system
It will be slow(ish) creating them, but at least they will be available for everyone.
I guess someday I’ll rewrite the plugin to make use of REDIS, Memcached… and then perhaps, something like AWS Elasticache or your own cache server can be used.
It’s on the roadmap, for when I have time…