=== Easy Critical CSS ===

Contributors:      criticalcss, sethta
Tags: critical css, unused css, performance, optimization, lighthouse
Requires at least: 6.2
Tested up to:      7.0
Requires PHP:      7.4
Stable tag:        1.4.8
License:           GPLv2 or later
License URI:       https://www.gnu.org/licenses/gpl-2.0.html

Easily inject Critical CSS and Secondary CSS (with unused CSS styles removed) to improve site speed and performance.

== Description ==

Easy Critical CSS is a lightweight WordPress plugin that lets you add Critical CSS to any page on your site to improve loading speed and performance.

**Features:**
- Easily add **Critical CSS** and **Secondary CSS** to any page
- **Secondary CSS** removes unused CSS rules and stylesheets, ensuring only a single optimized CSS file loads
- Supports **posts, pages, archives, and taxonomy pages**
- Fully **compatible with caching plugins** (WP Rocket, W3 Total Cache, WP Super Cache, etc.)
- **Customizable settings** for individual pages
- Stores Critical CSS in your choice of the **database or as static files**
- **Optional API service** (*API key required*) for automated Critical and Secondary CSS generation via [CriticalCSS.net](https://criticalcss.net/)
- **Background processing** to generate CSS without blocking page loads or admin actions

### Why Use Critical CSS?
Critical CSS ensures above-the-fold content loads first by reducing render-blocking CSS. This helps you **boost Core Web Vitals, improve page speed scores**, and deliver a better experience to your visitors.

Want to try it out first? You can generate free one-off Critical CSS at [CriticalCSS.net](https://criticalcss.net/#free-generator) and manually apply it to your site using the plugin settings.

== Installation ==

= Install via WordPress =

1. Visit **Plugins** > **Add New**.
2. Search for **Easy Critical CSS**.
3. Click **Install Now**, then **Activate**.

= Manual installation =

1. Download the plugin ZIP file.
2. Upload it to `/wp-content/plugins/` via FTP or WordPress plugin upload.
3. Activate it from the **Plugins** menu.

== External services ==

This plugin interacts with external third-party services in order to provide its functionality. Below is a detailed breakdown of these interactions:

1. **Critical CSS API (api.criticalcss.net)**
This service generates critical and secondary CSS used to optimize your site's CSS delivery and improve page load times.
 - **Data Sent**: The URL, CSS generation preferences, generation status, and HTML content of pages from your website.
 - **When**: Data is transmitted only if you have explicitly enabled the Auto generation mode, and occurs whenever Critical CSS or Secondary CSS needs to be generated or regenerated.
 - **Links**: [Terms of Service](https://criticalcss.net/terms/), [Privacy Policy](https://criticalcss.net/privacy/).

2. **Cloudflare API (api.cloudflare.com)**
This service is used to automatically clear your Cloudflare cache after new critical CSS is generated, ensuring your visitors see updated styles immediately.
 - **Data Sent**: Authentication credentials (Cloudflare email, API key, and zone ID) and instructions for purging the cache.
 - **When**: Data is sent only if `CLOUDFLARE_EMAIL`, `CLOUDFLARE_API_KEY`, and `CLOUDFLARE_ZONE_ID` are defined in your site's configuration.
 - **Links**: [Terms of Service](https://www.cloudflare.com/terms/), [Privacy Policy](https://www.cloudflare.com/privacypolicy/).

3. **Kinsta Cache Clear (localhost)**
If your site is hosted on Kinsta, this plugin can trigger a cache clear after generating new critical CSS, ensuring immediate availability of updated styles.
 - **Data Sent**: A cache-clear request to your site's local server endpoint provided by Kinsta. No sensitive or identifying information is transmitted beyond the local environment.
 - **When**: Data is sent only when your site detects that it’s running on Kinsta infrastructure (`KINSTA_CACHE_ZONE` environment variable is present).
 - **Links**: [Kinsta Terms of Service](https://kinsta.com/legal/terms-service/), [Kinsta Privacy Policy](https://kinsta.com/legal/privacy-policy/).

4. **Freemius API (api.freemius.com and wp.freemius.com)**
Used to manage licensing, validate API keys, and handle plugin updates and account management.  
 - **Data Sent**: Freemius sends and receives licensing information and plugin activation status, including your site's URL, plugin version, API key, and licensing details.
 - **When**: Data is transmitted only after explicitly opting in through the plugin's settings page or upon activation of a purchased API key. By default, the plugin does not send any data to Freemius until you explicitly opt in.
 - **Links**: [Freemius Terms of Service](https://freemius.com/terms/), [Freemius Privacy Policy](https://freemius.com/privacy/).

== Frequently Asked Questions ==

= Does Easy Critical CSS work with caching plugins? =
Yes! It integrates smoothly with popular caching plugins and clears their cache when Critical CSS updates, ensuring your visitors always see optimized styles.

= Can I exclude specific CSS files? =
Yes, the plugin allows you to specify **CSS files to exclude** from removal.

= How does the plugin generate Critical CSS? =
It integrates with [CriticalCSS.net](https://criticalcss.net), a fast and privacy-focused CSS generation service. It analyzes your page, extracts the above-the-fold styles, and returns optimized Critical and Secondary CSS automatically.

= Can I use this without an API key? =
Yes! You can manually enter Critical CSS for your entire site, or override it on specific pages. You don't need an API key unless you want automatic generation.

= How do I generate Critical CSS for manual usage? =
You can use the free generator at [CriticalCSS.net](https://criticalcss.net) to create both Critical and Secondary CSS for any page. Just copy the results into the appropriate fields in this plugin's settings.

= Where is Critical CSS stored? =
By default, Critical CSS and Secondary CSS are stored in your site's database. However, you can enable the **"Serve Critical CSS from Files"** option, which will save optimized CSS to static files inside `/wp-content/uploads/easy-critical-css/`. This can improve performance by reducing database load and serving CSS faster through your web server.
*Note: This setting applies only to auto-generated Critical CSS.*

= Is it safe to uninstall the plugin? =
Yes. If you choose the **"Delete All Data"** option under settings before uninstalling, all plugin settings and Critical CSS will be permanently removed from your site. If you simply deactivate or delete without using the uninstall option, your data will be preserved.

= Does Easy Critical CSS work with block themes and Full Site Editing? =
Yes, Easy Critical CSS is fully compatible with block-based themes and Full Site Editing (FSE) in WordPress 6.2 and above.

== Screenshots ==

1. Generate Critical CSS directly from the page editor with a single click.
2. The free generator autofills the page URL and sends results by email.
3. Active admin bar status confirms Critical CSS is running.

== Changelog ==

= 1.4.8 =
- IMPROVEMENT: Admin bar now shows more descriptive statuses when the site is unreachable
- IMPROVEMENT: Recent failures no longer list missing or expired API access as generation failures

= 1.4.7 =
- OPTIMIZATION: Improves Critical CSS status handling to reduce false error states
- OPTIMIZATION: Adds clearer status labels and tooltips for better page-level visibility
- OPTIMIZATION: Improves failure messaging to better guide next steps
- IMPROVEMENT: Adds quick access to generate free Critical CSS when using Manual mode

= 1.4.6 =
- OPTIMIZATION: Improve performance of compatibility functionality
- COMPATIBILITY: Adds Jetpack Boost compatibility
- COMPATIBILITY: Adds AddToAny compatibility

= 1.4.5 =
- OPTIMIZATION: Adds dismissible notification prompting users with active licenses to activate auto-generation
- FIX: Prevents manual CSS input fields from accepting URLs instead of CSS styles
- FIX: Removes unnecessary console logging

= 1.4.4 =
- FIX: Addresses an issue where transients clear too quickly on some server configurations.
- FIX: Prevents status checks from sending when no API key is present.

= 1.4.3 =
- OPTIMIZATION: Adds better REST API check with more details on Settings page
- OPTIMIZATION: Cleans up duplicate database rows that are formed when a post slug is changed
- COMPATIBILITY: Fixes compatibility issue with Perfmatters's Critical CSS feature
- FIX: Fixes issue where Expired statuses could not be cleared
- FIX: Fixes issue with status bar Regenerate button not working when conflicting plugins break REST API url
- FIX: Renames Excluded CSS Files to Always Loaded CSS Files when on Manual mode

= 1.4.2 =
- COMPATIBILITY: Adds EWWW Image Optimizer compatibility for lazy-loaded images
- COMPATIBILITY: Adds Perfmatters REST API compatibility
- FIX: Improves API key detection when new key has been added
- FIX: Clears cached status checks when settings are updated

= 1.4.1 =
- OPTIMIZATION: Allows larger Critical CSS payloads via REST API
- FIX: Fixes Cloudflare settings persistency issue

= 1.4.0 =
- FEATURE: Separates advanced settings for better usability
- FEATURE: Adds Cloudflare integration and advanced settings UI with privacy masking
- COMPATIBILITY: Adds 10Web Booster compatibility
- FIX: Fixes issue where stylesheets utilizing common CDNs were not being dequeued

= 1.3.1 =
- SECURITY: Invalidates handshake keys after use to prevent replay or brute force attempts
- SECURITY: Expires older/failed generation handshake keys automatically every 12 hours
- FIX: Prevents older queued Critical CSS generations from saving CSS if a new generation has been requested
- FIX: Runs Secondary CSS functionality only when Critical CSS has already been output

= 1.3.0 =
- FEATURE: Adds WooCommerce compatibility
- FEATURE: Hovering over the Critical CSS status now displays the size savings when using Secondary CSS
- FEATURE: Introduces new setting to auto include common Secondary selectors
- FEATURE: Creates new Settings buttons to quickly delete all and page-specific previously auto-generated styles
- FIX: Dedupes any user-added forced selectors
- FIX: Improves Cloudflare support

= 1.2.1 =
- OPTIMIZATION: Utilizes a preload swap to defer Secondary CSS instead of a print/media swap
- FIX: Prevents Auto mode calls from being sent to api.criticalcss.net when no API key has been added
- FIX: Compiles CSS more reliably when using fallback endpoint

= 1.2.0 =
- FEATURE: Adds Debug Mode setting with secure, locked-down endpoints
- FEATURE: Introduces new fallback endpointfor fetching page HTML and CSS, protected by a rolling handshake
- OPTIMIZATION: Adjusts default CSS service method to be static files instead of the database
- COMPATIBILITY: Fixes compatibility issue with WP Rocket's Critical CSS feature
- COMPATIBILITY: Addresses compatibility issue with Sucuri Website Firewall
- FIX: Respects Ignore Cross-Domain CSS setting when dequeuing stylesheets
- FIX: Improves reliability of Critical CSS expiration logic for individual posts and pages
- FIX: Prevents uptime-monitor User-Agents from triggering unnecessary regenerations

= 1.1.0 =
- FEATURE: Improves database structure for better performance and compatibility
- COMPATIBILITY: Adds compatibility with Trellis theme
- COMPATIBILITY: Fixes compatibility issue with WP Rocket
- FIX: Excludes additional non-page file types from generating Critical CSS
- FIX: Excludes non-SSL requests from generating Critical CSS
- FIX: Provides more accurate detection and fallback for Critical CSS settings

= 1.0.3 =
- FIX: Fixes issue where inline data SVGs were sometimes stripped
- FIX: Assigns proper status on non-published pages/posts

= 1.0.2 =
- FIX: Fixes logic when outputting Secondary CSS
- FIX: Prevents 404 pages from auto generating Critical CSS

= 1.0.1 =
- FIX: Prevents feeds from auto generating Critical CSS

= 1.0.0 =
- Initial release
- FEATURE: Manual Critical CSS adding
- FEATURE: Automated Critical CSS generation through API
- FEATURE: Integration with popular caching plugins

== Upgrade Notice ==

= 1.4.8 =
* Adds clearer unreachable-site statuses and cleans up failure reporting.

= 1.4.6 =
* This update provides compatibility improvements.

= 1.4.5 =
* This update includes bug fixes and improves code quality.

= 1.4.4 =
* This update provides bug fixes.

= 1.4.3 =
* This update provides compatibility improvements and bug fixes.

= 1.4.2 =
* This update provides compatibility improvements and bug fixes.

= 1.4.1 =
* This update provides bug fixes and optimizations to the plugin.
