=== Easy Optimizer – Speed, Cache, Unused CSS, Delay JS, Lazy Load, LCP & Core Web Vitals ===
Contributors: easywpstuff
Tags: performance, cache, pagespeed, core web vitals, lazy load
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 2.1.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

All-in-one speed optimizer: page cache, unused CSS removal, delay JS, lazy load, preload LCP, accessibility & SEO fixes. Boost Core Web Vitals free.

== Description ==

**Easy Optimizer** is a free, all-in-one WordPress performance plugin that replaces the 3–5 speed plugins most sites run today. One plugin. One dashboard. No premium upsells for core features.

Every toggle maps to a specific Google Lighthouse recommendation — enable it, save, and your Core Web Vitals (LCP, CLS, INP) improve immediately. Features you don't enable never touch your page load.

= Full Page Cache =

Static HTML served without PHP or database queries. Apache .htaccess mode delivers pages in under 1ms; PHP fallback works on Nginx, LiteSpeed and OpenLiteSpeed. Separate mobile/desktop cache, logged-in user caching with per-role variants, sitemap-based preloading, browser caching headers, and Gzip/Brotli compression — all automatic. Exclude URLs, cookies, query parameters, and tracking params (utm_source, fbclid) so one cached page serves all campaign links.

= Remove Unused CSS =

Tackles the highest-impact PageSpeed audit head-on. The plugin scans each page type, strips every CSS selector the DOM doesn't use, and outputs a slim stylesheet with only what's needed. You choose how original stylesheets are handled: delay until interaction (safest), async load, or full removal (advanced). Used CSS can be inlined or served as an external file. Separate mobile/desktop generation ensures themes like Astra, Kadence and GeneratePress keep their responsive classes intact. Auto-clears on post save and theme switch.

= Delay & Defer JavaScript =

Two methods to cut Total Blocking Time and improve INP. **Delay until interaction** holds all scripts until the visitor's first mouse, keyboard, touch or scroll event — best Lighthouse scores. **Defer** uses the browser's native defer attribute — scripts download in parallel and run after HTML parsing. jQuery excluded by default. Exclude by keyword, URL fragment or page path. Inline scripts can be externalized and delayed too.

= Lazy Load Images, Iframes, Videos & Backgrounds =

Offscreen media loads only when needed — images (WebP, AVIF, SVG), iframes (YouTube, Maps, embeds), videos and CSS background images. Uses WordPress core's WP_HTML_Processor for accurate parsing that skips noscript tags and the admin bar. Set "Exclude First N Images" to keep hero images eager. Auto-adds missing width/height attributes by reading image file headers — fixes the "Image elements do not have explicit width and height" audit and prevents CLS.

= Automatic LCP Preload =

Zero configuration. A lightweight PerformanceObserver beacon detects the LCP image on first visit. Every visit after that gets an automatic `<link rel="preload">` with `fetchpriority="high"` in the head and `loading="eager"` on the img tag. Results are stored per URL type and viewport (mobile/desktop) with a 30-day refresh.

= Prefetch Pages =

Makes your site feel like a single-page app. The EasyOptLink engine watches for in-viewport and hovered links, then pre-fetches or pre-renders them using the Speculation Rules API. When visitors click, the page is already cached in their browser. Four eagerness levels (conservative → immediate), configurable throttle and limit, plus URL and CSS selector exclusions.

= Font Optimization =

Adds `font-display: swap` to every @font-face — Google Fonts, inline styles, external stylesheets. Optional lazy-load font stylesheets defers font loading entirely, further cutting render-blocking resources.

= Image CDN =

Rewrites image URLs to the ShortPixel CDN for automatic WebP/AVIF conversion and compression. Works with img src, srcset, inline background-image CSS and Elementor background images. No API key needed for the default tier. Exclude images by URL fragment.

= Bloat Removal — 15 Toggles =

Disable what your site doesn't need: emoji scripts, oEmbed, XML-RPC, jQuery Migrate, version meta generator, RSD/WLW links, shortlinks, RSS feeds, self-pingbacks, REST API for logged-out visitors (smart allowlist for CF7, WPForms, Gravity Forms, WooCommerce, Gutenberg), Heartbeat API, WooCommerce cart fragments, Application Passwords, Dashicons for non-logged-in users, and Gutenberg Block Library CSS. Each toggle is independent.

= Database Cleanup & Optimization =

Remove revisions, auto-drafts, trashed posts, spam/trashed comments, expired or all transients, and optimize tables. Schedule daily, weekly or monthly. Automatic pre-cleanup snapshots let you restore if needed. The Autoload Health auditor shows total autoload size, lists the largest autoloaded options, and lets you toggle autoload off — with one-click re-enable and core option protection.

= Cloudflare Integration =

When Easy Optimizer clears its page cache, Cloudflare edge cache purges automatically. Supports tag-based purge (Enterprise) and full zone purge (all plans). Test your API connection before saving.

= Hosting Auto-Purge =

Auto-detects and integrates with Kinsta, WP Engine, SiteGround, Cloudways, GridPane, RunCloud, SpinupWP, Rocket.net and WordPress.com. Server-level cache purges alongside Easy Optimizer's cache automatically.

= Heartbeat & Cron Manager =

Control where Heartbeat runs and set custom frequency (15–300s). Throttle WP-Cron to every 2, 5 or 10 minutes without touching wp-config.php. View all scheduled cron events, run them manually or delete them.

= Accessibility Fixes =

Automatically fixes eight common Lighthouse accessibility failures using WordPress core's WP_HTML_Tag_Processor:

* Adds `aria-label` to inputs missing associated labels
* Adds `aria-label` to links with no discernible name
* Adds `aria-label` to buttons with no accessible name
* Strips `user-scalable=no` and `maximum-scale` restrictions from viewport meta
* Adds `aria-label` to elements with interactive ARIA roles but no accessible name
* Adds `title` to iframes/frames missing both title and aria-label
* Adds `aria-label` to progressbar elements without accessible names
* Resets `tabindex` values greater than 0 back to 0

= SEO Fixes =

* Rewrites anchor tags with missing, empty or `javascript:void(0)` hrefs to `href="#"` — fixes "Links are not crawlable"
* Generates alt text from image title or filename when alt is completely missing — fixes "Image elements do not have [alt] attributes"

= Modern Admin Dashboard =

Clean, tabbed settings interface. Caching, JavaScript, CSS, Lazy Load, Preload LCP, Prefetch Pages, Fonts, Image CDN, Bloat Removal, Cloudflare, Database Cleanup, Autoload Health, Heartbeat & Cron, Accessibility & SEO, and Settings — each in its own panel. Real-time cache stats, preload progress, quick-action buttons, collapsible help sections, and JSON import/export for easy migration.

= PageSpeed Insights & Lighthouse Recommendations Addressed =

* Reduce initial server response time (TTFB) — page cache
* Eliminate render-blocking resources — unused CSS removal, font-display:swap
* Reduce unused CSS — per-page-type used CSS generation
* Reduce unused JavaScript — delay JS until interaction
* Minimize main-thread work — delay and defer JavaScript
* Defer offscreen images — lazy load images
* Serve images in next-gen formats — ShortPixel CDN (WebP/AVIF)
* Properly size images — add missing width and height
* Image elements do not have explicit width and height — auto-dimension injection
* Preload Largest Contentful Paint image — automatic LCP detection and preload
* Ensure text remains visible during webfont load — font-display:swap
* Serve static assets with an efficient cache policy — browser caching headers
* Enable text compression — Gzip/Brotli rules
* Form elements do not have associated labels — accessibility fix
* Links do not have a discernible name — accessibility fix
* Buttons do not have an accessible name — accessibility fix
* [user-scalable="no"] in viewport or [maximum-scale] < 5 — viewport fix
* Frame or iframe elements do not have a title — accessibility fix
* ARIA progressbar elements do not have accessible names — accessibility fix
* Some elements have a [tabindex] value greater than 0 — tabindex fix
* Links are not crawlable — SEO fix
* Image elements do not have [alt] attributes — SEO fix

= Works With Your Setup =

* **WordPress:** 6.4+  |  **PHP:** 7.4+
* **Servers:** Apache, Nginx, LiteSpeed, OpenLiteSpeed
* **Hosting:** All providers. Auto-integrates with Kinsta, WP Engine, SiteGround, Cloudways, GridPane, RunCloud, SpinupWP, Rocket.net, WordPress.com
* **WooCommerce:** Fully compatible — cart, checkout and my-account automatically excluded from caching, unused CSS, lazy load, delay JS and CDN
* **Page Builders:** Elementor, Beaver Builder, Divi, Gutenberg, Bricks, Oxygen, Breakdance
* **CDN:** Cloudflare built-in. Works with Bunny, KeyCDN, StackPath, Fastly
* **Themes:** Astra, Kadence, GeneratePress, OceanWP, Flavor and all standards-compliant themes
* **Multilingual:** Translation-ready with full textdomain support


== External Services ==

This plugin optionally rewrites image URLs to ShortPixel's CDN to serve optimized images:

* Service: ShortPixel CDN (https://cdn.shortpixel.ai/)
* What it does: When "Image CDN" is enabled, image URLs are rewritten so visitors' browsers request images from ShortPixel's CDN, enabling WebP/AVIF delivery.
* What data is sent: Only the image URL. No site data or personal information is transmitted.
* Links: [ShortPixel Privacy Policy](https://shortpixel.com/privacy) | [ShortPixel Terms of Service](https://shortpixel.com/terms-of-service)

== Frequently Asked Questions ==

= Does this replace WP Rocket, LiteSpeed Cache or W3 Total Cache? =
Yes — page caching, unused CSS, delay JS, lazy loading, LCP preload, font optimization, image CDN, database cleanup, bloat removal, accessibility and SEO fixes all in one free plugin. Disable other caching plugins before enabling the page cache.

= Does it work with WooCommerce? =
Fully. Cart, checkout and my-account pages are automatically excluded from all optimization modules. Cart fragments can be disabled separately from the Bloat Removal tab.

= Will Delay JavaScript break my site? =
Most sites work without issues. jQuery is excluded by default. If something breaks, add the script name to the exclusion list or switch to the safer Defer method.

= Can I use this with Cloudflare? =
Yes. Add your API token and Zone ID in the Cloudflare tab. Cache purges sync automatically.

= Does it support multisite? =
Works on individual sites within a multisite network. Network-wide activation is in testing.

= How do I migrate settings between sites? =
Export settings as JSON from the Settings tab, then import on the destination site.

= What's the best starting configuration? =
Enable Page Cache, Remove Unused CSS, Delay JavaScript, Lazy Load Images, Preload LCP and Font Display Swap. Then turn on the accessibility and SEO toggles relevant to your site.

== Installation ==

1. Install via **Plugins → Add New** and search "Easy Optimizer", or upload to `/wp-content/plugins/easy-optimizer/`.
2. Activate the plugin.
3. Go to **Easy Optimizer** in the admin sidebar.
4. Enable Page Cache and Remove Unused CSS first — they have the biggest impact.
5. Save. The cache preloader starts warming your site automatically.

== Screenshots ==

1. Dashboard — performance overview with cache statistics, preload progress, feature status toggles and quick-action buttons for clearing cache and Cloudflare.
2. Cache settings — page cache with serving mode selection (PHP or .htaccess), cache lifetime, separate mobile cache, browser caching, Gzip/Brotli, preload toggle and granular exclusion fields.
3. JavaScript optimization — delay until interaction or native defer method, jQuery exclusion, script and URL exclusion lists, inline script externalization.
4. CSS optimization — remove unused CSS with inline or file method, stylesheet behavior (delay, async, remove), selector and stylesheet exclusion, per-post-type mode.
5. Lazy load — toggle images, iframes and videos independently; add missing dimensions; exclude first N images; class and URL exclusion.
6. LCP preload — automatic detection with zero configuration; URL exclusion for edge cases.
7. Prefetch pages — speculation rules eagerness, prerender toggle, throttle and limit controls, URL and CSS selector exclusions.
8. Font optimization — font-display:swap and lazy-load font stylesheets with exclusion support.
9. Image CDN — ShortPixel CDN toggle with Elementor background image support and image URL exclusion.
10. Bloat removal — 15 independent toggles for emojis, embeds, XML-RPC, jQuery Migrate, version meta, RSD/WLW, shortlinks, RSS, self-pingbacks, REST API, Heartbeat, cart fragments, App Passwords, Dashicons and Block Library CSS.
11. Cloudflare — API token and zone ID with test connection button, purge strategy selection.
12. Database cleanup — task toggles with item counts, scheduled cleanup, snapshot and restore, chunked processing.
13. Autoload health — total autoload size, per-option size breakdown, one-click autoload disable/enable with core option protection.
14. Heartbeat & Cron — heartbeat location and frequency control, WP-Cron throttle, cron event viewer with manual run and delete.
15. Accessibility & SEO — eight accessibility audit toggles and two SEO audit toggles with clear Lighthouse audit descriptions.
16. Settings — import/export JSON and delete-on-uninstall control.

== Privacy ==

Easy Optimizer includes optional anonymous usage tracking to help improve the plugin. Disabled by default — only enabled after explicit opt-in. No personal data, site content, emails, IPs, usernames or passwords are ever collected.

== Changelog ==

= 2.1.0 =
* New: Optimization tab split into 5 sub-tabs — JavaScript, CSS, Lazy Load, Preload LCP and Prefetch Pages
* New: Database tab split into 2 sub-tabs — Database Cleanup and Autoload Health
* New: Heartbeat & Cron tab — consolidates Heartbeat API control, WP-Cron throttle and Cron Event Manager
* New: Settings tab with Import/Export and "Delete all plugin data on uninstall" toggle
* New: Collapsible help sections throughout all panels
* New: Dependency check on Lazyload Fonts when Remove Unused CSS is not enabled
* New: Disable Block Library CSS toggle in Bloat Removal
* New: Rewrite Elementor Background Images toggle in Image CDN panel
* New: Stylesheet Behavior "Remove" option with inline breakage warning
* Improved: "Instant Load" renamed to "Prefetch Pages" for clarity
* Improved: Cache exclusion fields displayed in compact 3-column grid
* Improved: Preload Cache enabled by default with auto-restart on cache clear
* Improved: Admin toolbar "Clear All Cache" triggers preload restart when preload is enabled
* Performance: pre_option shim uses prefix-based early exit
* Performance: Database cleanup counts moved to async REST API call

= 2.0.3 =
* New: Heartbeat API control with location and frequency settings
* New: WP-Cron frequency throttle using transient-based lock
* New: Cron Event Manager with manual run and delete
* New: Defer JavaScript method as alternative to delay
* New: Separate mobile/desktop Used CSS generation
* New: Autoload Health auditor
* New: Expanded mobile safelist for Used CSS
* Fixed: Cloudflare test connection no longer requires pre-save
* Improved: Dashboard module rows fully clickable

= 2.0.2 =
* Improved: Database snapshot restore

= 2.0.1 =
* Improved: Performance optimizations for conditional module loading

= 2.0.0 =
Major architecture rewrite with 25+ new features including page cache, cache preload, remove unused CSS, delay JavaScript, LCP preload, prefetch pages, font optimization, database cleanup with snapshots, Cloudflare integration, 9 hosting integrations, 8 accessibility toggles, 2 SEO toggles, 15 bloat removal toggles and a new admin dashboard.

= 1.1 =
* Initial release with lazy load and Image CDN.

== Upgrade Notice ==

= 2.1.0 =
New sub-tab navigation, Heartbeat & Cron manager, Settings import/export, Block Library CSS toggle and performance improvements. Existing settings fully preserved.