Customize Remove Unused CSS parameters

Filters for High CPU caused by Remove Unused CSS 

You can change  the number of URLs per batch, and the CRON interval of the Remove Unused CSS optimization. This might help to reduce the CPU usage in those cases where it is caused by this optimization.

We have two filters to achieve this:

  • rocket_rucss_pending_jobs_cron_rows_count : A lower value (default is 100 URLs) can help the server to work on fewer requests at a time.
  • rocket_rucss_pending_jobs_cron_interval : By setting a higher value (default is 60 seconds), the server will have more time to rest between processing batches.

You can use this helper plugin to achieve it:

📥 Download (.zip): WP Rocket | Change Remove Unused CSS Parameters

Developers: You can find the code for this plugin on GitHub.

Important! You must edit the helper plugin before use!

Only install this plugin if you are comfortable editing files via (S)FTP! This plugin itself works; however, in case something conflicts in your custom environment, you might need to remove this plugin manually via (S)FTP and edit your .htaccess directly.

Instructions to use this helper plugin

  1. In the helper, the values are already changed so you can install it as it is. Or you can cet your custom values by editing:
    • Line 26, to set the batch size. It is the number of URLs that will be processed on each run. The default is 100, the helper will set this to 50.
    • Line 46, to set the desired cron interval in seconds. It is the pause that will be applied between the processing of batches. The default is 60 seconds, the helper will set it to 120 seconds
  2. Compress it as ZIP, upload and activate the helper plugin
  3. Changes will be applied the next time you clear the Used Css and the generation is triggered again

Other Remove Unused CSS filters

Additionally, you can change other parameters such as

  • With the rocket_used_css_dir_level filter you can change the allowed subfolders. 

    The default value is  3 folders.
  • Remove Unused CSS will preserve style tags in the page's source code. You can use the rocket_rucss_preserve_inline_style_tags filter can be used to exclude <style> elements from being preserved.
  • If needed, the rocket_rucss_external_exclusions filter can be used to preserve external stylesheets. 
  • If needed, the rocket_rucss_inline_content_exclusions filter can be used to preserve inline CSS. See further guidance and the related helper plugin in this article.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.