=== VaryCache ===
Contributors: gkap186
Tags: cache, a/b testing, geo targeting, personalization, performance
Requires at least: 5.0
Tested up to: 6.9
Stable tag: 1.2.3
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Advanced caching with A/B testing, geo-targeting, and speed optimizations. Serve different cached versions of pages.

== Description ==

VaryCache is a powerful WordPress caching plugin that combines page caching with content personalization. Serve different cached versions of your pages based on A/B tests, visitor location, or URL parameters — all while maintaining excellent performance.

= Core Caching =

* **Page Cache** - File-based caching for fast page delivery without database overhead
* **REST API Cache** - Cache REST API responses to reduce server load
* **Cache Preload** - Automatic cache warming from sitemap
* **Browser Cache Headers** - Cache-Control, Expires, Last-Modified, Vary headers

= Content Personalization =

* **A/B Testing** - Create multiple tests with weighted variants (50/50, 70/30, etc.)
* **Geo Targeting** - Show different content based on visitor's country
* **Query Parameters** - Cache variations based on UTM tags and other URL parameters

= Speed Optimizations =

* **HTML Minification** - Remove whitespace to reduce page size
* **DNS Prefetch** - Pre-resolve external domains for faster loading
* **Preload Resources** - Preload fonts, CSS, and hero images for better LCP
* **Link Prefetch** - Preload pages on hover for instant navigation
* **Disable Emoji** - Remove WordPress emoji scripts (~15KB savings)
* **Remove Query Strings** - Better CDN caching for static resources
* **Image Dimensions** - Auto-add missing width/height to prevent CLS
* **Gzip Compression** - Compress HTML output to reduce page size by ~70%

= Developer Features =

* **Shortcodes** - Easy content switching in posts and pages
* **PHP Functions** - Helper functions for theme developers
* **Debug Panel** - Visual debugging panel on frontend
* **CDN Compatible** - Works with CloudFront, Cloudflare, and other CDNs
* **Translation Ready** - Includes Russian translation

= Shortcodes =

`[varycache_ab v="A"]Content for variant A[/varycache_ab]`
`[varycache_ab v="B"]Content for variant B[/varycache_ab]`
`[varycache_ab test="pricing" v="X"]Content for specific test[/varycache_ab]`
`[varycache_geo country="US"]Content for US visitors[/varycache_geo]`

= PHP Functions =

`// A/B Testing
if ( varycache_is_variant( 'A' ) ) {
    // Show variant A content
}
$variant = varycache_get_variant(); // Returns 'A', 'B', etc.

// Geo Targeting
if ( varycache_is_geo( 'US' ) ) {
    // Show US-specific content
}
$country = varycache_get_geo(); // Returns 'US', 'RU', etc.`

= Page Patterns =

Flexible page matching with wildcards and regex:

* `/` - Homepage only
* `/pricing` - Exact page match
* `/blog/*` - Single level wildcard
* `/shop/**` - Any depth wildcard
* `~^/post/\d+$` - Regular expression (prefix with ~)

= Requirements =

* WordPress 5.0 or higher
* PHP 7.4 or higher
* Write access to wp-content directory

== Installation ==

1. Upload the `varycache` folder to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Go to Settings > VaryCache to configure

= Quick Start =

1. Enable caching in the plugin settings
2. Configure Page Cache to cache all pages or specific URLs
3. Optionally set up A/B tests, geo targeting, or query parameters
4. Use shortcodes in your content to show different versions to different visitors

= Using with Other Cache Plugins =

If using another caching plugin, exclude pages with variant caching from that plugin's cache. VaryCache will handle caching for those pages with variant support.

== Frequently Asked Questions ==

= What makes VaryCache different from other caching plugins? =

VaryCache combines page caching with content personalization. Unlike traditional caching plugins that serve the same cached page to everyone, VaryCache can serve different cached versions based on A/B tests, visitor location, or URL parameters.

= Can I use VaryCache just for page caching without A/B testing? =

Yes! You can use VaryCache purely as a page cache. Enable "General Page Cache" in the Page Cache tab and configure which pages to cache. A/B testing, geo targeting, and query parameters are optional features.

= How does geo targeting detect the visitor's country? =

VaryCache reads country information from HTTP headers provided by CDNs:
- CloudFront: `CloudFront-Viewer-Country`
- Cloudflare: `CF-IPCountry`
- Custom: You can configure your own header name

If no header is detected, the country code will be "XX".

= Does this work with page builders like Elementor? =

Yes! The shortcodes work with any page builder including Elementor, Gutenberg, Divi, WPBakery, and others. Simply add the shortcode blocks where needed.

= How are visitors assigned to A/B test variants? =

Visitors are randomly assigned based on the weights you configure (e.g., 50% variant A, 50% variant B). The assignment is stored in a cookie so they see the same variant on subsequent visits.

= Does A/B testing affect SEO? =

No. Search engine bots see the default variant, and the canonical URL remains unchanged. This is the recommended approach per Google's guidelines for A/B testing.

= What are the speed optimization features? =

VaryCache includes several Core Web Vitals optimizations:
- **HTML Minification** - Reduces page size by removing whitespace
- **DNS Prefetch** - Pre-resolves external domains (Google Fonts, Analytics, etc.)
- **Preload Resources** - Preloads critical fonts, CSS, and hero images (improves LCP)
- **Disable Emoji** - Removes WordPress emoji scripts (~15KB savings)
- **Image Dimensions** - Adds missing width/height to prevent layout shifts (CLS)
- **Gzip Compression** - Compresses HTML output to reduce page size by ~70%
- **Link Prefetch** - Preloads pages when user hovers over links

= How does REST API caching work? =

You can configure specific REST API endpoints to be cached (e.g., `/wp/v2/posts`). Cached responses are served directly without executing PHP, significantly reducing server load for API-heavy sites.

= Where are cache files stored? =

Cache files are stored in `wp-content/cache/varycache/`. Settings are stored in `wp-content/uploads/varycache/settings.json`. Both locations are WordPress-compliant.

= Can I clear the cache programmatically? =

Yes, use `VaryCache_Cache::clear_cache()` in your code. The cache is also automatically cleared when posts are saved or deleted.

= Does VaryCache work with CDNs? =

Yes, but for A/B testing and geo targeting to work correctly, configure your CDN to:
- Pass through cookies (for A/B test variant assignment)
- Forward country headers (for geo targeting)

== Screenshots ==

1. VaryCache admin panel - flexible caching plugin for dynamic content

== Changelog ==

= 1.2.3 =
* NEW: Gzip Compression - compress HTML output by ~70% for faster loading
* Core Web Vitals improvement: reduced page size for better performance

= 1.2.0 =
* NEW: Speed optimization tab with Core Web Vitals features
* NEW: HTML Minification - reduce page size by removing whitespace
* NEW: DNS Prefetch - pre-resolve external domains for faster loading
* NEW: Preload critical resources (fonts, CSS, images) for better LCP
* NEW: Remove query strings from static resources for better CDN caching
* NEW: Disable WordPress emoji scripts to save ~15KB
* NEW: Auto-add missing image dimensions to prevent CLS
* IMPROVED: Reorganized admin UI with logical grouping
* IMPROVED: Moved Link Prefetch and Browser Cache to Speed tab
* IMPROVED: Better separation of concerns in code
* Core Web Vitals optimizations: LCP, CLS improvements

= 1.1.0 =
* NEW: REST API caching - cache REST endpoints to reduce server load
* NEW: Cache Preload - automatic and manual cache warming from sitemap
* NEW: Browser Cache Headers - Cache-Control, Expires, Last-Modified, Vary
* NEW: Page Cache admin tab with all caching settings
* NEW: Test REST endpoints for debugging (/varycache/v1/test)
* IMPROVED: Admin interface with better organization
* IMPROVED: WordPress.org compliance updates
* IMPROVED: Changed prefix from 'vc' to 'varycache' per WordPress.org guidelines
* IMPROVED: Moved settings file to uploads directory per WordPress.org guidelines
* IMPROVED: Scripts now properly enqueued using wp_enqueue_script
* FIX: Various security improvements and code cleanup

= 1.0.0 =
* Initial release
* A/B testing with weighted variants
* Geo targeting via CloudFront/Cloudflare headers
* Query parameter caching
* Page pattern matching (wildcards, regex)
* Admin settings panel with tabs
* Cache management and reporting
* Debug panel
* Shortcodes and PHP helper functions

== Upgrade Notice ==

= 1.2.3 =
New Gzip Compression feature reduces page size by ~70%. Enable in Speed tab for immediate performance boost.

= 1.2.0 =
New Speed tab with Core Web Vitals optimizations: HTML minification, DNS prefetch, preload hints, disable emoji, image dimensions. Highly recommended update for better performance.

= 1.1.0 =
New features: REST API caching, Cache Preload, Browser Cache Headers. Recommended update.

= 1.0.0 =
Initial release.
