Rajat Kumar Verma Releases CSS Class Collector Module for Safe CSS Purging in Drupal
Rajat Kumar Verma has released CSS Class Collector, a new Drupal module that improves frontend performance by enabling safe CSS purging through automatic detection of CSS classes used in database-driven content.
This utility module compiles a reliable list of all classes actively used on a site, offering a trustworthy safelist for tools like PurgeCSS, Tailwind CSS, and Bootstrap. The goal is to eliminate unused CSS safely without affecting layouts or breaking functionality, particularly when dynamic or backend-generated classes are involved.
Developers working with bootstrap_barrio or custom themes can leverage this module to streamline their optimisation workflows. It supports scenarios where precision is critical for performance tuning, especially when using modern CSS frameworks.
To implement CSS purging with the module, users are instructed to copy bootstrap.min.css and build-css.js from the module into their theme directory. Running node build-css.js from that location generates a trimmed-down CSS file, keeping only the necessary classes detected from live content.
The automation ensures cleaner stylesheets and faster site performance, all while maintaining Drupal’s design integrity across content types and user interfaces.
