Troubleshoot Used CSS generation issues
This guide will help you if you notice that Remove Unused CSS's Used CSS generation is slow or not working at all.
In this Article
Used CSS generation overview
By default, Used CSS generation will schedule up to 100 new URLs for optimization per batch every 60 seconds. However, there is also a maximum total number of 300 URLs allowed to be scheduled for optimization at any particular time (keeping this total low helps prevent errors).
The number of URLs and the frequency can be customized, to speed up or slow down the generation, as shown in the Customize Remove Unused CSS parameters article.
Activating the Preload feature will automate this process.
However, this maximum default generation speed depends on the factors addressed below in this article: allowing the connection; configuration of security plugins and firewalls; reliability of cron; and overall status of Action Scheduler.
Quick fixes
- Regenerate Used CSS
If you notice Used CSS is not applied to your page(s), in most cases, regenerating the Used CSS will be the solution. You can do this by clicking the Clear Used CSS or Clear Used CSS of this URL buttons in WP Rocket's top admin menu.
Note: Used CSS generation may randomly time out, for example, if your server is temporarily overloaded. Regenerating Used CSS manually is a legitimate first troubleshooting step, which usually helps bypass any false-positives. - Clear additional cache layers
Additionally, if your site is using another layer of cache, such as server-side page caching, you should clear that cache layer to see if that helps. - Truncate the wpr_rucss_used_css table
HEADS UP!: Please, only truncate the wpr_rucss_used_css after you made a backup of your site.
If the above quick fixes still don't help, please continue reading for more guidance.
Connection requirements
The Used CSS won't be generated if there is no connection between WP Rocket's server and your site.
Please check the following basic requirements:
- You must have a valid WP Rocket license.
- Your site must be publicly accessible for the tool to work, which means it won’t be applied to logged-in users when User Cache is enabled, and it won't work on sites blocked from the public by htaccess authentication, "maintenance mode" plugins, or similar.
Note: This feature is automatically disabled in environments where theWP_ENVIRONMENT_TYPE
constant is set to local, because it needs to establish a connection with WP Rocket's tool to generate the Used CSS. -
WP Rocket will reach the non-cached version of the page to scan the CSS. It will reach the pages of your site with the
?wpr_imagedimensions=1&nowprocket=1&no_optimize=1
query string appended. Access to this query string must be allowed. The non-cached page shouldn't take more than 45 seconds to load, or it will time out in WP Rocket's SaaS. - Your server, firewall, and/or security plugin has to allow-list:
- These two user agents:
- Desktop:
WP-Rocket/SaaS Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
- Mobile:
WP-Rocket/SaaS Mozilla/5.0 (Linux; Android 13; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Mobile Safari/537.36
- Desktop:
-
And/or, the IPs found in this list.
- These two user agents:
Security plugins and firewalls
The following services may detect Used CSS generation requests as a potential risk and block them. Please take the following in consideration:
- If you are using Wordfence, activate Learning Mode as described here.
- Cloudflare's Bot Fight Mode should be disabled as shown here.
Used CSS won't be generated if your plugins or firewalls are blocking WP Rocket's server.
When WP Rocket can't access your site, the following admin notice will be displayed:
It seems a security plugin or the server's firewall prevents WP Rocket from accessing the Remove Unused CSS generator. IPs listed here in our documentation should be added to your allowlists:
- In the security plugin, if you are using one
- In the server's firewall. Your host can help you with this
If the resulting Used CSS is smaller than 150 bytes (150 characters), because, for example, WP Rocket's SaaS is being blocked by a security plugin or a captcha, then it will be considered as invalid CSS and WP Rocket won't apply it to your pages. In this case, your pages will keep using the original CSS.
Cron issues
The Used CSS generation and further application heavily depends on cron. So, whether you're using WP Cron or a server side cron job, you should make sure the frequency of occurrence is reliable and high enough.
You can learn how to check the status of cron, and how to log cron's ocurrence by checking the How to check if cron is running correctly article.
Action Scheduler issues
Action scheduler tables
WP Rocket uses the wp_actionscheduler_
tables to handle Used CSS generation. The following message will be displayed if WP Rocket can't create Action Scheduler tables:
WP Rocket: We detected missing database table related to Action Scheduler. Please visit the following URL to recreate it, as it is needed for WP Rocket to work correctly.
This problem is usually caused by a misconfiguration with the database encoding, or can happen after a server migration, but clicking on the link in the notice should fix this. If the notice doesn't go away, or Used CSS doesn't seem to be generated, please contact support.
Scheduled tasks queue
If there are dozens or hundreds of pending actions in the Scheduled Actions dashboard, the Used CSS generation will be queued and stopped. We recommend clearing the pending actions, making sure cron is working and contact support.
Monitoring Used CSS generation
WP Rocket tracks Used CSS generation via the database, and places the resulting Used CSS file is located in the file system.
You can check the wpr_rucss_used_css
table to track the progress of Used CSS generation via a plugin such as SQL Buddy or using a database management software such as phpMyAdmin.
When checking the table, you can see the Used CSS generation status in the status column, here:
The database will have a status
column, with five possible values, as follows:
to-submit
- Initial status for all pages that are triggered for Used CSS generation, meaning the page needs to have Used CSS generated, but processing is not scheduled yet.pending
- Status for pages that have been submitted to be processed in the generator, meaning processing is scheduled but has not started yet.in-progress
- Status for when Used CSS is currently being processed by the generator.completed
- Status confirming that the generator has successfully created the Used CSS for the URL.failed
- Status when a request was not successful, i.e, it doesn't send a200 (OK)
status code. In this case, theerror_code
anderror_message
columns will show more details.
The resulting Used CSS will be located in the /wp-content/cache/used-css/ folder, within a system of subfolders, whose names depend on the first characters of the hash assigned in the wpr_rucss_used_css
table.
See the following short recording to have an idea of how the Used CSS is stored:
The Used CSS file is stored using the CSS.GZ compression format, to save disk space.
Since checking the CSS files within all the subfolders may be a tedious task, the recommendation is to use the database if you need to track Used CSS generation.