Probably not. Here’s why.
The reason it breaks is that a lot of inline JS depends on jQuery. And if you’ve deferred jQuery to run after everything is loaded, then the inline JS will be calling jQuery functions that haven’t been declared yet. This throws an error and spoils your page functionality.
So if you want to defer jQuery, you only have the following options:
- Remove all inline JS
- Rewrite your inline JS to not use jQuery
- Use my method to defer inline JS
Option 1 is usually undesirable. Who wants to reduce the functionality of their page? Option 2 is usually unfeasible because the inline JS typically comes from plugins and themes. And even if you were open to modifying their source code, you might not know how to rewrite them without a jQuery dependency.
Option 3 is (so far) still the best.
What Does the new Autoptimize Setting Do?
Sounds good right? Not so fast.
This Causes Your Cache to Grow FAST!
But using this option will cause the cache to balloon quickly, as the plugin struggles to create unique copies for each different combination of files and inline JS. It’s not a good idea unless you have a very specific configuration.
Just Use My “module” Method Instead
So until Autoptimize finds a better solution to this, I’m not recommending anyone to use the new “Aggregate inline JS” option.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Leave a Reply