A PHP script to analyze which CSS classes and IDs from a stylesheet are used in a project's template files, and which are not. This helps in cleaning up unused CSS to reduce file size and improve maintainability.
- PHP 8.1 or newer.
- A local web server (like Apache, Nginx, or using PHP's built-in server).
-
Clone the repository:
git clone [https://github.com/olelasse/CSS-Usage-Analysis.git](https://github.com/olelasse/CSS-Usage-Analysis.git) cd CSS-Usage-Analysis -
Create your configuration file: Copy the sample configuration file.
cp config/config.php.sample config/config.php
-
Edit
config/config.php: Openconfig/config.phpand update the paths to point to your project's folders.stylesheets: Path to the CSS file you want to analyze.templates: Path to the folder containing your PHP/HTML template files where the CSS selectors are used.
- Point your web server's document root to the
/publicdirectory of this project. - Open your browser and navigate to the project's URL (e.g.,
http://localhost/). - The analysis report will be generated and displayed automatically.