# WP Recache — Open Source Performance Plugin
## Overview
Create a commercial-grade, open source (GPL-2.0+) WordPress performance plugin providing page caching, file optimization, and image optimization. Features are written from specification, never derived from any existing plugin's source code.
## Specification-First Methodology
### Rules
1. **No code reuse.** Never copy, paste, or adapt PHP/JS/CSS from any existing performance plugin.
2. **Feature specs only.** Features are specified from a *user perspective* (UI behavior, options, output), not from anyone's implementation.
3. **Independent implementation.** All code written from scratch using WordPress APIs and standard libraries.
4. **Documentation trail.** Keep records of the specification process to prove independent development.
### What We Study (User Perspective)
- Admin UIs of established performance plugins: what settings exist, what they control
- Frontend output: what HTML/JS/CSS changes appear after activation
- Behavior: when cache clears, what gets optimized, what's excluded by default
- Performance: what metrics improve
### What We Ignore
- PHP source code structure
- Internal class/function naming
- Specific implementation patterns
- Hook naming conventions
## Feature Specifications
### 1. Page Cache
**User-facing behavior:**
- On first anonymous visit, generates static HTML file
- Subsequent anonymous visits serve the static file directly
- Cache auto-purges when content is published/updated
- Manual purge available from admin bar and settings page
- Excludes logged-in users, cart/checkout pages, specific URLs
- Separate cache for mobile devices (optional)
- Preload/crawl sitemap to warm cache
**Technical approach (independent implementation):**
- Use WordPress `advanced-cache.php` drop-in
- Output buffering via `ob_start()` / `ob_get_contents()` / `ob_end_flush()`
- Cache files stored in `wp-content/cache/`
- Serve cached files via direct file read before WordPress loads
- Use WordPress rewrite rules for cache detection
### 2. File Optimization — CSS
**User-facing behavior:**
- Minify CSS files (remove whitespace, comments)
- Combine CSS files into fewer requests
- Defer non-critical CSS loading
- Remove unused CSS (RUCSS — Remove Unused CSS)
- Inline critical CSS for above-the-fold content
- Async CSS loading
**Technical approach:**
- Use CSS minification library (e.g., `natanielrodman/css-minify` or similar)
- Parse CSS to identify critical path selectors
- Output buffering to detect and modify `` tags
- Generate critical CSS via headless browser or parser
### 3. File Optimization — JavaScript
**User-facing behavior:**
- Minify JavaScript files
- Combine JavaScript files
- Defer JavaScript loading (load after HTML parsed)
- Delay JavaScript execution (load on user interaction)
- Remove jQuery Migrate
- Delay inline scripts
**Technical approach:**
- Use JavaScript minification (e.g., `tedivm/jshrink` or similar)
- Output buffering to modify `