=== WPSwings AI Website Optimizer ===
Contributors: wpswings
Donate link: https://wpswings.com/
Tags: performance, cache, speed, optimization, lazy load
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Full-page caching, HTML/CSS/JS minification, lazy loading, image optimization, and WordPress housekeeping — all from one plugin.

== Description ==

WPSwings AI Website Optimizer is a comprehensive WordPress performance plugin that combines full-page caching, asset optimization, media lazy loading, database cleanup, WooCommerce-specific tuning, and CDN integration into a single, React-powered admin interface.

= Caching Engine =

* **Full-page HTML caching** — Serve pre-built static HTML instead of rebuilding pages on every request
* **Configurable cache lifetime** — Set how long cached pages stay valid (1–720 hours)
* **Separate mobile cache** — Optionally store a distinct copy for mobile visitors
* **Auto-purge on update** — Automatically clear a page's cache when its content is saved
* **Cache exclusions** — Exclude specific URLs or path patterns from caching
* **Logged-in user exclusion** — Never serve cached HTML to logged-in users

= CSS, JS & HTML Optimization =

* **Minify HTML** — Strip whitespace, comments, and redundant quotes from rendered HTML
* **Minify CSS & JS** — Compress both enqueued and inline stylesheets and scripts
* **Remove duplicate CSS rules** — Drop exact-duplicate rule blocks and repeated selectors
* **Compress CSS values** — Shorten `0px` to `0`, `#ffffff` to `#fff`, and similar
* **Defer JavaScript** — Stop scripts blocking the initial render
* **Move JS to footer** — Relocate scripts from `<head>` to the footer where safe
* **Remove jQuery Migrate** — Drop the jQuery backward-compatibility script
* **Combine CSS / Combine JS** — Merge multiple compatible local files to reduce HTTP requests
* **Critical CSS generation** — Inline above-the-fold CSS and defer the rest (off by default — the most invasive option)
* **Remove Unused CSS** — Track selectors across real page visits and drop ones never matched (conservative heuristic, off by default)
* **Delay JavaScript until interaction** — Hold non-critical scripts until the visitor scrolls, clicks, or taps
* **Per-page asset manager** — Disable specific scripts or styles on individual posts/pages from the editor
* **DOM & rendering diagnostics** — Reports oversized DOM trees and render-blocking assets (diagnostic only — does not alter markup)
* **Disable WordPress extras** — Remove emoji CSS, Dashicons (front-end), oEmbed stylesheet, block editor CSS, and version query strings

= Image & Media / Lazy Load =

* **Lazy load images** — Defer offscreen images with native `loading="lazy"` and a JS fallback
* **Responsive lazy loading** — Defer `srcset`/`sizes` attributes on responsive images
* **Lazy load iframes, videos, and HTML5 video** — Defer generic iframes and self-hosted `<video>` elements
* **YouTube / Vimeo / Google Maps facades** — Replace embed iframes with click-to-load previews (no third-party request until clicked)
* **Placeholder images** — Show a lightweight placeholder while the real image loads
* **Fade-in animation** — Fade images in once they load instead of popping in abruptly
* **Dominant color placeholders** — Extract each image's real average color (computed once per image, cached)
* **LQIP placeholders** — Show a tiny blurred preview of the actual image (computed once per image, cached)
* **Image compression** — Recompress uploaded images and generated thumbnails to reduce file size (JPEG-optimized; GD only)
* **WebP generation** — Create `.webp` siblings alongside uploaded images, served via a `<picture>` fallback wrapper
* **Original backup** — Back up pre-compression bytes before optimizing so "Restore Original" stays possible
* **Above-the-fold exclusion** — Never lazy-load the first N images to protect LCP scores

= Database & Cleanup =

* **Disable emojis, embeds, XML-RPC, oEmbed, shortlinks, RSD, WLW Manifest**
* **Remove generator meta tag** — Hide the WordPress version from page source
* **Remove version query strings** — Strip `?ver=` from static asset URLs
* **Heartbeat API control** — Disable or throttle the Heartbeat API
* **Disable RSS feeds, pingbacks, and trackbacks**
* **Scheduled database optimization** — Automatically clean up revisions, auto-drafts, trashed posts, spam comments, and expired transients
* **Dry-run mode** — Preview what the cleanup would remove before actually deleting anything
* **Orphaned meta cleanup** — Remove post meta and comment meta rows left after their parent was deleted

= WooCommerce Optimization =

* **Cart fragments optimization** — Load the cart-fragments AJAX request only where the cart is shown, or disable it entirely
* **Optimize checkout scripts** — Trim non-essential scripts (gallery, zoom, etc.) from the checkout page
* **Disable WooCommerce JS/CSS on non-shop pages** — Only enqueue WooCommerce assets where needed
* **Cache related products** — Fragment-cache the related-products block on product pages
* **Checkout Blocks safe mode** — Skip JS defer/delay/footer-move on block-based Cart and Checkout pages to protect WooCommerce Blocks hydration
* **Optimize My Account assets** — Trim unused scripts/styles on account endpoint pages
* **Disable unused WooCommerce widgets** — Prevent widget assets loading when unused

= Server & CDN Integration =

* **CDN URL rewriting** — Rewrite same-site image, CSS, and JS URLs to a merchant-configured CDN hostname
* **Works with any origin-pull CDN** — No API keys or provider-specific integration required
* **Exclusion patterns** — Skip specific URLs or wildcards from CDN rewriting

== Installation ==

1. Upload the plugin files to `/wp-content/plugins/wpswings-ai-website-optimizer/` or install via the WordPress plugin installer
2. Activate the plugin through the **Plugins** menu in WordPress
3. Navigate to **WPSwings Optimizer** in the admin menu to configure each module

== External Services & Privacy ==

This plugin does not connect to any external services, does not send any data to third parties, and does not use any AI APIs or cloud services. All processing (caching, minification, image compression, lazy loading) happens entirely on your server.

= Vimeo oEmbed =

When the **Lazy load Vimeo embeds** feature is enabled and a Vimeo embed is found on the page, the plugin makes a single request to Vimeo's public oEmbed endpoint (`https://vimeo.com/api/oembed.json`) to retrieve the video's real thumbnail URL. This request:

* Is made from your server, not the visitor's browser
* Is cached locally for 30 days, so it happens at most once per video
* Sends only the public Vimeo video URL, nothing else
* Is governed by Vimeo's own privacy policy at https://vimeo.com/privacy

If you do not enable Vimeo lazy loading, no request is ever made to Vimeo.

= No Other External Services =

The plugin makes no other external HTTP requests. All data (cache files, minified assets, combined files, image backups, usage tracking for Remove Unused CSS) is stored locally within `wp-content/cache/wpsaiwo/` or the WordPress database.

== Building From Source ==

This plugin includes compiled JavaScript assets in `admin/build/`. The human-readable source code is in `admin/src/`.

= Build Requirements =

* Node.js 16+ and npm
* The plugin uses Vite for building React components

= Build Steps =

1. Navigate to the `admin/` directory
2. Install dependencies: `npm install`
3. Build for production: `npm run build`
4. Development mode with hot reload: `npm run dev`

The build process compiles React/JSX source files from `admin/src/` into bundled JavaScript and CSS in `admin/build/`.

== Frequently Asked Questions ==

= Do I need WordPress 7.0 for this plugin to work? =

No. The plugin works with WordPress 6.0+. It is tested up to WordPress 7.0.

= Does this plugin require WooCommerce? =

No. All modules except **WooCommerce Optimization** work independently of WooCommerce. The WooCommerce module is simply unavailable when WooCommerce is not active.

= Is it safe to enable all toggles at once? =

We recommend enabling features incrementally and testing after each group. A few features are explicitly off by default because they are more aggressive or site-specific: Critical CSS generation, Remove Unused CSS, Delay JavaScript, Remove optional closing tags, and the database cleanup options. The admin UI includes a description and scope note on each toggle.

= What is "dry-run mode" for database cleanup? =

When dry-run mode is on, the plugin previews what the scheduled cleanup would delete without actually removing anything. It is on by default — review a few preview runs before enabling live cleanup.

= Can I restore images after compression? =

Yes. If **Keep original backup** is on, the plugin saves each image's pre-compression bytes to `wp-content/cache/wpsaiwo/media-originals/{attachment_id}/`. A "Restore Original" action is available per attachment that swaps the compressed file back.

= Does this plugin make any external HTTP requests? =

Only one: when Vimeo lazy loading is enabled, the plugin fetches a Vimeo video thumbnail via Vimeo's public oEmbed API (once per video, cached 30 days). See **External Services & Privacy** above for full details. No other external requests are made.

= Does this plugin use AI? =

The plugin name includes "AI" as part of the WPSwings product family branding. It does not call any AI or machine-learning APIs. All optimizations are deterministic, server-side operations.

= Does this work in a multisite network? =

The plugin activates and stores settings per-site. Full network-wide management is planned for a future version.

= Cart, checkout, and account pages are cached — is that safe? =

No — they are never cached. WooCommerce cart, checkout, and account pages are always automatically excluded from the page cache when WooCommerce is active.

== Screenshots ==

1. Dashboard overview — module cards with on/off toggles and live status indicators
2. Caching Engine settings — page cache, TTL, mobile cache, purge controls, and exclusions
3. CSS, JS & HTML Optimization — minification, defer, footer-move, combine, critical CSS, and more
4. Image & Media / Lazy Load — native and JS lazy loading, placeholder options, WebP and compression settings
5. Database & Cleanup — cleanup categories with dry-run mode and scheduled optimization controls
6. WooCommerce Optimization — cart fragments, checkout scripts, related products cache, and Blocks safe mode
7. Server & CDN Integration — CDN hostname configuration and per-resource rewrite toggles
8. Per-page asset manager — classic editor meta box listing enqueued scripts and styles

== Changelog ==

= 1.0.0 - 2026-07-27 =
* Initial release
* Full-page HTML caching with auto-purge and mobile cache support
* HTML, CSS, and JavaScript minification
* Defer JS, move JS to footer, remove jQuery Migrate
* Critical CSS generation (above-the-fold inlining)
* Remove Unused CSS tracker (conservative heuristic)
* Combine CSS and Combine JS (bundles local assets into fewer files)
* Delay JavaScript until interaction with configurable fallback timeout
* Per-page asset manager (editor meta box)
* DOM and rendering diagnostics
* Native and JS-fallback lazy loading for images, iframes, and HTML5 video
* YouTube, Vimeo, and Google Maps click-to-load facades
* Placeholder images with dominant color and LQIP support
* Fade-in animation for lazy-loaded images
* Image compression and WebP generation (GD, on-upload and bulk)
* Restore-original support for compressed images
* WordPress cleanup toggles (emojis, embeds, XML-RPC, pingbacks, etc.)
* Heartbeat API control
* Scheduled database optimization with dry-run mode
* WooCommerce optimization (cart fragments, checkout, catalog, My Account)
* Related-products fragment cache with per-product invalidation
* Checkout Blocks safe mode to protect WooCommerce Blocks hydration
* CDN integration — rewrite image, CSS, and JS URLs to a custom hostname
* React-powered admin interface

== Upgrade Notice ==

= 1.0.0 =
Initial release of WPSwings AI Website Optimizer.

== Privacy Policy ==

This plugin:
* Does not collect or transmit any user data to external services
* Does not set any cookies
* Does not track visitors
* Stores all generated cache files, minified assets, and optimization data locally in `wp-content/cache/wpsaiwo/`
* Stores plugin settings and usage-tracking data (for Remove Unused CSS) in the WordPress database
* Makes one external request per Vimeo video (to fetch a thumbnail via Vimeo's public oEmbed endpoint) when Vimeo lazy loading is enabled — this request is cached locally for 30 days

For information about how Vimeo handles thumbnail API requests, refer to the Vimeo Privacy Policy at https://vimeo.com/privacy.

== Credits ==

* Developed by WP Swings
* Admin interface built with React and the WordPress REST API
* Image processing uses PHP GD (no external image service)
