- What does jbsnewmedia/css-purger do in a Laravel app?
- CssPurger removes unused CSS rules from stylesheets used by your Laravel application. It works by scanning Blade views and rendered HTML to find which classes are actually used, then strips rules that do not match. This is especially useful for trimming large CSS frameworks like Bootstrap.
- How do I install jbsnewmedia/css-purger with Composer?
- Install the package with Composer using the name jbsnewmedia/css-purger. After installation, follow the package's Laravel setup instructions for any required configuration or registration. Run your first purge in a staging environment before applying it to production stylesheets.
- How does CssPurger decide which CSS rules are unused?
- It scans the HTML and Blade templates you point it at and collects the CSS class names that appear in the markup. Any CSS rule whose selectors do not match those detected classes is treated as unused and removed. Whitelisting lets you protect classes that are added dynamically and would otherwise be missed.
- Can CssPurger scan both Blade views and rendered HTML?
- Yes, the package is described as scanning Blade views and rendered HTML for class usage. Scanning rendered HTML helps catch classes that appear after Laravel renders a view, while Blade scanning covers template source. Use both approaches where possible to reduce false positives.
- How do I whitelist dynamic classes that JavaScript adds at runtime?
- CssPurger provides whitelisting so classes that do not appear in scanned Blade or HTML output are not purged. Add the class names used by your JavaScript components, toggles, modals, and third-party widgets to the whitelist. Review the whitelist after adding new frontend behavior, and test interactions in staging.
- Does CssPurger work with Bootstrap and other CSS frameworks?
- Yes, the package is intended for optimizing large stylesheets such as Bootstrap based on actual usage in your project. Frameworks often include many rules your app never uses, so purging can shrink the final CSS. Test every major component and state, because framework classes can be applied conditionally.
- Is it safe to purge CSS in a production Laravel application?
- Purging can be safe if you test thoroughly, keep backups of the original CSS, and whitelist dynamic classes. Because CssPurger removes rules based on detected usage, missing classes from JavaScript or user-generated content can cause visual regressions. Start in staging, compare key pages, and only then deploy the purged stylesheet.
- How do I configure CssPurger for my Laravel project?
- Configuration focuses on which templates or HTML sources to scan and which class names to whitelist. Check the package documentation for the exact configuration file and option names for your version. Begin with a conservative whitelist and a staging purge so you can review the diff before production.
- Which Laravel versions are supported by CssPurger?
- The provided package context does not list supported Laravel versions. Check the package's composer.json and README for version constraints before installing it in your application. If your Laravel release is not confirmed, test the package in a separate branch or staging environment first.
- Can I use CssPurger outside Laravel or with plain PHP?
- The package overview calls CssPurger a lightweight PHP library, while the package blurb presents it as a Laravel package. It may be usable in plain PHP if the core library is exposed, but confirm that in the documentation. For Laravel projects, use the documented Laravel integration to scan Blade views and rendered HTML.