Why Autoptimize Creates Multiple CSS Files and How to Fix It
Content
If you're using Autoptimize to speed up your WordPress site, you might have noticed it sometimes generates multiple CSS files instead of a single, aggregated one. This can be confusing and may seem to defeat the purpose of using an optimization plugin. Let's break down why this happens and the most common solutions to consolidate your stylesheets.
Why Multiple CSS Files Appear
Based on community discussions and troubleshooting, Autoptimize creates multiple CSS files for a few key reasons:
- Default Exclusions: To prevent its cache from growing uncontrollably, Autoptimize by default excludes CSS files located in
wp-content/uploadsandwp-content/cachefrom aggregation. Many page builders (like Elementor) and themes store dynamic, page-specific CSS in these folders. When excluded, these files are processed individually, resulting in additionalautoptimize_single_...files. - Inline CSS Handling: The "Also aggregate inline CSS?" option can sometimes cause issues. If certain inline CSS patterns are present (like the
.wp-container-classes introduced in WordPress 5.9), they can cause cache busting and multiple file generation. Newer versions of Autoptimize automatically handle this, but older installations might need a manual fix. - Third-party or External CSS: Autoptimize cannot aggregate CSS from external, third-party sources (like Google Fonts or CDNs). These will always remain as separate requests.
- Plugin or Theme Conflicts: Occasionally, a conflict with another plugin or your theme can interfere with Autoptimize's aggregation process, preventing it from working correctly.
How to Consolidate CSS into a Single File
Here are the most effective solutions, drawn from resolved support threads, to achieve a single aggregated CSS file.
1. Modify CSS Exclusion Rules
The most common fix is to adjust what Autoptimize is allowed to aggregate. By default, it excludes CSS in certain directories. You can change this.
- Go to Autoptimize → CSS Options.
- Look for the "Exclude CSS from Autoptimize:" text field.
- The default value often includes
wp-content/uploads. You can try removing this exclusion. - Save changes and clear your Autoptimize and page caches.
Important Note: Removing this exclusion might cause your Autoptimize cache size to increase significantly, as it will now store a unique CSS file for every page that has unique uploads CSS. Monitor your cache directory if you do this.
2. Check the "Also Aggregate Inline CSS" Setting
If you are using an older version of Autoptimize and WordPress 5.9 or newer, inline CSS can cause problems.
- Ensure your Autoptimize plugin is updated to the latest version, as versions 2.9.5.1 and newer automatically handle WordPress 5.9's inline CSS.
- If you cannot update, you can manually add
.wp-container-to the CSS exclusion list as a temporary workaround.
3. Identify Conflicting Plugins or Code
If the above steps don't work, a conflict might be preventing aggregation.
- Temporarily disable other caching or optimization plugins (e.g., SG Optimizer, WP Super Cache) to see if Autoptimize then works correctly.
- Switch to a default WordPress theme (like Twenty Twenty-Four) to rule out a theme-specific issue.
- Check if any custom code in your
functions.phpfile is dequeuing stylesheets. Remember, Autoptimize works after the enqueuing process, so it will only aggregate styles that are actively enqueued by your theme and plugins.
4. Understand the Limits: External CSS
Autoptimize cannot combine CSS from external domains. For files like //ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css, the only solution is to host a copy of the file on your own server and enqueue it locally before Autoptimize can process it.
When Multiple Files Are Okay
It's important to note that having a couple of CSS files is not always a bad thing. With modern HTTP/2 servers, the overhead of multiple small requests is reduced. The goal is to find a balance that delivers the best performance score for your specific site. Sometimes, excluding a very large, plugin-specific CSS file (like Elementor's) can be a more effective strategy for overall performance than forcing everything into one massive bundle.
By understanding these common causes and solutions, you can better configure Autoptimize to work with your specific WordPress setup and achieve optimal loading times.
Related Support Threads Support
-
CSS Order Changed for @import Statementshttps://wordpress.org/support/topic/css-order-changed-for-import-statements/
-
Aggregated PHP file instead CSShttps://wordpress.org/support/topic/aggregated-php-file-instead-css/
-
Do not remove css versionshttps://wordpress.org/support/topic/do-not-remove-css-versions/
-
Remove CSS from Minified/Combined URLhttps://wordpress.org/support/topic/remove-css-from-minified-combined-url/
-
Minify CSS filehttps://wordpress.org/support/topic/minify-css-file/
-
Aggregating CSS adds new CSS that doesn’t exist in my codehttps://wordpress.org/support/topic/aggregating-css-adds-new-css-that-doesnt-exist-in-my-code/
-
Does `/wp-content/uploads/ao_ccss/` contain old css ?https://wordpress.org/support/topic/does-wp-content-uploads-ao_ccss-contain-old-css/
-
No CSS Aggregation With Custom WP_CONTENT_URLhttps://wordpress.org/support/topic/no-css-aggregation-with-custom-wp_content_url/
-
Why are there multiple CSS files for Elementor?https://wordpress.org/support/topic/why-are-there-multiple-css-files-for-elementor/
-
Feature Request: Aggregate Files into X number of fileshttps://wordpress.org/support/topic/feature-request-aggregate-files-into-x-number-of-files/
-
Include 3rd Party CSS in Minify/Combinehttps://wordpress.org/support/topic/include-3rd-party-css-in-minify-combine/
-
The plugin removes file versionshttps://wordpress.org/support/topic/the-plugin-removes-file-versions/
-
“Also aggregate inline CSS” doesn’t seem to be doing anythinghttps://wordpress.org/support/topic/also-aggregate-inline-css-doesnt-seem-to-be-doing-anything/
-
How to find the name of aggregates CSS and JS filehttps://wordpress.org/support/topic/how-to-find-the-name-of-aggregates-css-and-js-file/
-
Autotomize not aggregating CSShttps://wordpress.org/support/topic/autotomize-not-aggregating-css/
-
Autoptimize & WordPress 5.9 issue with aggregated inline CSS: fixhttps://wordpress.org/support/topic/autoptimize-wordpress-5-9-issue-with-aggregated-inline-css/
-
Aggregate CSS/Javascript in a single filehttps://wordpress.org/support/topic/aggregate-css-javascript-in-a-single-file/
-
Filter for modifying aggregated csshttps://wordpress.org/support/topic/filter-for-modifying-aggregated-css/
-
Static files generatedhttps://wordpress.org/support/topic/static-files-generated/
-
Multiple autoptimze CSS versionshttps://wordpress.org/support/topic/multiple-autoptimze-css-versions/
-
Multiple CSS files created with Autoptimizehttps://wordpress.org/support/topic/multiple-css-files-created-with-autoptimize/
-
First agregate with Autoptimize and then dequeue or the other way around?https://wordpress.org/support/topic/first-agregate-with-autoptimize-and-then-dequeue-or-the-other-way-around/
-
Feature Request: Remove Unused CSShttps://wordpress.org/support/topic/feature-request-remove-unused-css-2/
-
Pinpoint Plugin Targetinghttps://wordpress.org/support/topic/pinpoint-plugin-targeting/
-
Post Update Issue with Autoptimize v 3.1.13https://wordpress.org/support/topic/post-update-issue-with-autoptimize-v-3-1-13/
-
How to set up relative path to the optimized css and js files?https://wordpress.org/support/topic/how-to-set-up-relative-path-to-the-optimized-css-and-js-files/
-
wp-includes not aggregated, why?https://wordpress.org/support/topic/ap-includes-not-aggregated-why/
-
How does Autoptimize treast @import?https://wordpress.org/support/topic/how-does-autoptimize-treast-import/