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:
You can use the helper as is, or further customize it. In both cases, changes will be applied the next time you clear the Used Css and the generation is triggered again.
Slow down the generation of the Used CSS with default helper values
The helper already sets the parameters to slow down the generation of the Used CSS, so you can install it as it is.
When this helper is used as it is:
- The number of URLs per batch will be reduced from 100 to 50 URLs per run.
- The cron interval will be slowed down from 60 seconds to 120 seconds.
Slow down or speed up the generation of the Used CSS with customization
Important! In this part, 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.
You can set your custom values to this helper plugin by editing:
- Line 26, to set the batch size. It is the number of URLs that will be processed on each run.
- Decrease in case the default value is causing a higher CPU usage. This will result in the server running shorter tasks.
- Increase progressively if you have enough resources to process long standing tasks.
- Line 46, to set the desired cron interval in seconds. It is the pause that will be applied between the processing of batches.
- Increase in case the default value is causing a higher CPU usage. The server will have more time to rest between processing batches.
- Decrease progressively if you don't notice any increase in CPU load.
Then, compress the helper as ZIP, upload it and activate it.
Other Remove Unused CSS filters
Additionally, you can change other parameters such as:
- With the
rocket_used_css_dir_levelfilter 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_tagsfilter can be used to exclude
<style>elements from being preserved.
- If needed, the
rocket_rucss_external_exclusionsfilter can be used to preserve external stylesheets.
- If needed, the
rocket_rucss_inline_content_exclusionsfilter can be used to preserve inline CSS. See further guidance and the related helper plugin in this article.