• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

Using the New Autoptimize Aggregate Inline JS

Bhagwad Park

Published on: August 9, 2021

Categories: WordPress 0

On the 26th of July, 2021, the well-known plugin Autoptimized released a new update that allows for deferring in-line JavaScript. Here’s the new option as seen in the settings screen:

Autoptimize Aggregate Inline JS

This new ability, lets you final defer inline JavaScript so that it doesn’t mess up your page load times. But should you enable it? And is it better than the method I came up with last year to defer inline JS?

Probably not. Here’s why.

The Problem of Inline JavaScript

Ideally, we would want to defer all our JavaScript to the very end of the HTML. This is particularly true for libraries like jQuery that are huge, and significantly slow down the page load times. Unfortunately, doing this is likely to break a lot of inline JavaScript – the stuff that’s woven into our HTML, and that provides many useful functions like copy/paste buttons, etc.

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:

  1. Remove all inline JS
  2. Rewrite your inline JS to not use jQuery
  3. 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?

The new Autoptimize setting called “Aggregate Inline JS” does just that. It extracts the inline JavaScript and adds it to the cache that already contains the aggregated JavaScript from all the JS files on your page. So yes – the inline JS will still fail. But it’ll run again once the final JS file has been downloaded, and this time it’ll work correctly because jQuery has finally been downloaded and the functions declared.

Sounds good right? Not so fast.

This Causes Your Cache to Grow FAST!

The above solution is problematic because Autoptimize will create a cached file that’s likely to be different for each page or post. Often, the inline JavaScript code contains varies not just from page to page, but also possibly from user to user, or based on the time! So Autoptimize will start creating a unique cached copy of the JS files for each of these versions. Your cache can start expanding to unmanageable levels!

Under normal circumstances without the “Aggregate Inline JS” option, this isn’t a problem because most pages load the same set of static JS files. There’s very little variation, and you’re not adding special, constantly changing external JavaScript to the page. So Autoptimize can create a small bundle of cached files, and be done with it.

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

In the technique to which I linked at the beginning of this article, I was able to defer inline JS execution by changing the script declaration from type=”text/javascript” to <script type=”module”>. This solution avoids all the messy problems with caching above, and simply forces the JS to run after jQuery has been downloaded.

So until Autoptimize finds a better solution to this, I’m not recommending anyone to use the new “Aggregate inline JS” option.

Bhagwad Park Profile Picture
Bhagwad Park

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!

Related Posts

Blogger vs. WordPress: Which One to Use?

Let's compare WordPress and Blogger across five key areas. Then, we'll show you how to set up a professional blog with WordPress.

How To Start A Newsletter In WordPress

Check out our complete guide on why and how you should start your own newsletter in WordPress.

Joomla vs. WordPress: Which One Is Better?

In this post, we’ll consider five differences between Joomla and WordPress and how you might go forward with setting up a WordPress website.

What Is Self-Hosted WordPress?

In this post, we’ll differentiate self-hosted WordPress from WordPress.com, and discuss the benefits of the former.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA