"You killed Kenny! You bastards!" — But your CSS doesn't have to die unused anymore.
A lightweight PHP tool that crawls your WordPress site (or any website), analyzes all internal pages and stylesheets, and generates a cleaned-up CSS file containing only the selectors you actually use. Perfect for optimizing load times, improving Core Web Vitals, and boosting SEO by cutting dead weight.
- Smart Crawling — Recursively scans internal pages up to your specified limit
- CSS Extraction — Pulls all linked stylesheets and inline styles
- Intelligent Matching — Detects which CSS selectors are actually used in your HTML
- Pseudo-Class Handling — Correctly handles
:hover,:focus,:before,:after, etc. - Statistics Dashboard — Shows original vs. cleaned selector count and percentage saved
- Zero Dependencies — Pure PHP, no composer packages or external libraries
- Download Ready — Generates timestamped CSS files for easy versioning
- PHP 7.4 or higher (8.x recommended)
allow_url_fopenenabled in php.ini- Basic web server (Apache, Nginx) or PHP built-in server
- Sufficient memory for large sites (adjust
memory_limitif needed)
-
Upload the script to your web server or run locally:
php -S localhost:8000
-
Open in your browser and enter:
- Your website URL (e.g.,
https://yoursite.com) - Number of pages to scan (5–50 recommended)
- Your website URL (e.g.,
-
Hit Scan — The tool will:
- Crawl your site
- Extract all CSS files
- Analyze selector usage
- Generate
cleaned_css_YYYY-MM-DD_HHMMSS.css
-
Download the cleaned CSS and replace your bloated stylesheet
- Start Small — Test with 5-10 pages first to verify results
- Use Staging — Run on a development/staging site before production
- Verify Output — Always test the cleaned CSS thoroughly before deploying
- Backup First — Keep your original CSS safe (obviously)
- Re-run Periodically — After major design changes or plugin updates
- Crawling Phase — Starts at your URL, finds all internal links, follows them recursively
- CSS Collection — Extracts
<link rel="stylesheet">references from each page - Selector Parsing — Breaks down CSS into individual selectors and rules
- Usage Detection — Checks if classes, IDs, and tags exist in the combined HTML
- Generation — Outputs only the selectors that matched
The tool uses intelligent pattern matching:
- Class selectors (
.button) → Checks forclass="...button..." - ID selectors (
#header) → Checks forid="header" - Tag selectors (
div,h1) → Checks for<div>,<h1>tags - Pseudo-classes (
:hover,:focus) → Stripped during matching but kept in output - Universal selectors (
*) → Always kept - Media queries (
@media) → Always preserved
- JavaScript-generated content — Won't detect classes added via JS after page load
- Dynamic CMS content — May miss styles used on unpublished/draft pages
- Complex selectors — Advanced combinators like
.parent > .child:nth-of-type(2n+1)are matched simplistically - Inline styles — Not analyzed (only external/internal
<style>tags in CSS files) - Page limit — Crawling 100+ pages may timeout; adjust
set_time_limit()or increasemax_pagesgradually
For best results:
- Scan multiple page types (homepage, blog posts, products, etc.)
- Include pages with different layouts/templates
- Test the output thoroughly before replacing production CSS
- Memory Issues? → Increase
memory_limit = 256Min php.ini - Timeouts? → Increase
max_execution_time = 300or reduce page count - Slow Crawling? → Check your server's outgoing connection speed
- Huge CSS Files? → Consider breaking them into smaller chunks first
Unused CSS is a silent killer:
- 🐌 Slows down page rendering (browser has to parse everything)
- 📉 Hurts Google PageSpeed Insights scores
- 💸 Wastes bandwidth (especially on mobile)
- 😤 Frustrates users with slow load times
This tool helps you:
- ⚡ Reduce CSS file size by 40-80% (typical results)
- 🚀 Improve First Contentful Paint (FCP) and Largest Contentful Paint (LCP)
- 📈 Boost SEO rankings through better Core Web Vitals
- 🧹 Clean up after years of plugin/theme bloat
Scan läuft...
Scanne: https://example.com
CSS gefunden: https://example.com/wp-content/themes/mytheme/style.css
Scanne: https://example.com/about
Scanne: https://example.com/contact
Bereinige CSS...
✅ Fertig!
Seiten gescannt: 10
Originale Selektoren: 2,847
Verwendete Selektoren: 623
Eingespart: 78.1%
📥 Download: cleaned_css_2024-12-14_153042.css
Found a bug? Want to add features? PRs welcome!
Potential Improvements:
- Add support for
<style>inline blocks - Integrate JavaScript selector detection
- Generate before/after comparison reports
- Add whitelist/blacklist for specific selectors
- Support for CSS-in-JS frameworks
Created by Volkan Sah (GitHub)
A developer passionate about performance optimization and making the web faster for everyone.
Other Projects:
** GNU GENERAL PUBLIC LICENSE Version 3**
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
- ⭐ Like it? Star the repo!
Remember: Always test cleaned CSS before going live. This tool is smart, but you're smarter. 🧠
Readme.md crafted with help of AI - PHP Code crafted by Volkan Sah