=== PyCoreWeb Optimizer – Page Cache, Unload Unused CSS & JS, Delay JS, WebP ===
Contributors: pirajki
Tags: cache, performance, speed, unload assets, critical css
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.9.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Speed up WordPress safely: page cache, unload unused CSS and JS per page, delay JS, critical CSS, hero image boost, lazy load and WebP.

== Description ==

PyCoreWeb Optimizer makes pages load faster by removing what a page does not need and loading the rest smarter. Everything is built to be safe: every change can be tried in test mode first, core files can never be removed, and one click shows any page without optimizations.

= One-click setup =

* Choose "Recommended" or "Maximum" on the Dashboard and every matching feature is set for you, with test mode on first so only you see the result. One click undoes it.

= Page Cache =

* Pages are saved as static HTML files and served before WordPress loads the theme, so pages arrive in a few milliseconds.
* Works on any host without server setup. On Apache and LiteSpeed you can also let the server send cached pages directly (optional rules in .htaccess).
* Separate copies for phones, no cache for logged-in users, carts, checkouts and comment authors.
* Cleared automatically when you publish or update content, comments, menus, widgets, themes, plugins and Elementor styles; only the pages affected are cleared where possible.
* Cache preload: your sitemap and recent posts are cached in the background, so the first visitor also gets a fast page.
* Admin bar buttons to clear the whole cache or just the current page.

= More Speed =

* Hero image boost: the main background image of Elementor pages is found and preloaded with high priority, the WebP copy and a phone-sized version are used where available. This is usually the Largest Contentful Paint.
* Below-the-fold rendering: sections further down the page are only drawn when the visitor scrolls near them, and their background images load at that point.
* Instant page loads: the next page starts loading when the visitor points at or touches a link.
* Local Google Fonts: Google Fonts are downloaded once to your site and served from there.
* Light video embeds: YouTube and Vimeo videos show a preview image and only load the player when clicked.
* WordPress tweaks: switch off emojis, embeds, XML-RPC, dashicons for visitors and more, and slow down or stop the Heartbeat.
* Database cleanup: revisions, auto-drafts, trashed posts, spam and trashed comments, expired transients, with an optional schedule.

= Unload Files =

* See every CSS and JavaScript file a page really loads. The list comes from loading the page as a logged-out visitor, grouped by theme, plugin, WordPress core and external services.
* Switch files off on the whole site, or on single pages from the editor.
* Group rules: unload a file on groups of pages, or load it only where it is needed. Groups include page types (front page, blog, archives, search, 404, author, date…), post types including custom ones, categories, tags and custom taxonomy terms, page templates, logged-in or logged-out visitors, address patterns, and WooCommerce shop, product, cart, checkout and account pages.
* Exact matching only: switching off one file never removes others with similar names.
* Files that another loaded file depends on keep loading, so nothing breaks because of a missing dependency.
* Core files such as jQuery and the WordPress JavaScript runtime are protected and can never be unloaded.

= CSS & JavaScript =

* Defer JavaScript using WordPress's own loading strategy, which keeps the script order.
* Delay chosen scripts (chat widgets, analytics, pixels) until the visitor first scrolls, taps or moves the mouse, or delay all JavaScript. A tap made while scripts load is replayed once they are ready. Elementor and WooCommerce scripts that must run right away are kept, and cart and checkout pages are never delayed.
* Load stylesheets without blocking the page from showing.
* Critical CSS generated automatically in your own browser while you view a page. No outside service, no account and no data sent anywhere. You can also paste your own critical CSS for the whole site or for any page.
* Minify CSS and JavaScript. Minified copies are cached and refreshed automatically when a file changes; files that are already minified are left alone, and your originals are never changed.
* Preload fonts and hero images, preconnect to other domains, and use font-display: swap for Google Fonts and theme.json fonts.

= Images =

* Native lazy loading for images and iframes, skipping the first images at the top of the page.
* Missing width and height filled in, so the page does not jump while images load.
* WebP (and AVIF where your server supports it) copies created next to your originals, for new uploads and with a bulk tool for existing images. Served with the picture element, so older browsers still get the original. Your original files are never changed.

= Safe by design =

* Test mode: only logged-in administrators see the optimizations until you are happy.
* "View this page without optimizations" in the admin bar, or add `?pyco_off=1` to any address while logged in as an administrator.
* Emergency off switch: add `define( 'PYCO_DISABLE', true );` to wp-config.php.
* Every option is off by default except safe image improvements.

= PyCoreWeb Optimizer Pro =

Everything described above is free and stays free. An optional Pro add-on from [Py CoreWeb](https://pycoreweb.com/) adds time-savers for larger sites, such as generating critical CSS for the whole site in the background. The free plugin never needs it.

== Installation ==

1. Install the plugin from Plugins > Add New, or upload the `pycoreweb-optimizer` folder to `/wp-content/plugins/`.
2. Activate it.
3. Open **PyCoreWeb Optimizer** in the admin menu. Turn on test mode from the Dashboard while you try things out.
4. On **Unload Files**, scan your home page and switch off files it does not need. For single pages, use the **Unload Files** box in the editor.
5. When everything looks right, turn test mode off.

== Frequently Asked Questions ==

= Can I load a file only on the pages that need it? =

Yes. On Unload Files, press "Rules…" next to the file, choose "Load only on these pages" and add the groups, for example "Pages" and "Template: Contact". The file is unloaded everywhere else. A contact form plugin's files are a typical example.

= Will this break my site? =

It is built not to. Core files are protected, dependencies keep loading, and every CSS and JavaScript option is off until you switch it on. Use test mode to try changes as an administrator before visitors see them.

= Something looks wrong. How do I turn everything off? =

Use "View this page without optimizations" in the PyCoreWeb admin bar menu to compare. To switch the plugin off everywhere at once, add `define( 'PYCO_DISABLE', true );` to wp-config.php, or deactivate the plugin.

= Does it send my data anywhere? =

No personal data is sent anywhere. The file scan and cache preload load your own site from your own server. Critical CSS is generated in your browser and saved to your own database. Only the optional Local Google Fonts and Light video embeds features fetch files from Google, YouTube or Vimeo; see "External services" below.

= Do I still need another caching plugin? =

No. Turn on Page Cache and switch off the page cache of other plugins, so pages are not cached twice. The Page Cache screen warns you when it finds another cache. If you prefer to keep your host's or another plugin's cache, leave Page Cache off and clear that cache after changing settings.

= Where are cached pages stored? =

In `wp-content/uploads/pycore-optimizer/cache/`. Deleting the plugin removes them.

= I use Nginx. Can the server send cached pages directly? =

Page Cache works without any server rules. For the fastest path on Nginx, ask your host to try `$uri` under `/wp-content/uploads/pycore-optimizer/cache/$host$uri/index.html` before passing the request to PHP, for GET requests without a query string and without WordPress login, comment or WooCommerce cart cookies.

= Why is "Load CSS without blocking" not doing anything? =

It only runs on pages that have critical CSS, so visitors never see an unstyled page. Keep "Generate critical CSS automatically" on and view a page while logged in, or paste critical CSS yourself.

= Is JavaScript minification safe? =

It runs in a safe mode: comments, indentation and extra spaces are removed, but line breaks that JavaScript can rely on are kept, so scripts run exactly as before. It was checked against all of WordPress core's own scripts. If a script still misbehaves, add it to "Never minify".

= Where are WebP files stored? =

Next to the original, with the extra extension added: `photo.jpg` gets `photo.jpg.webp`. Use "Delete all WebP/AVIF copies" on the Images screen to remove them, for example before deleting the plugin.

= Some images could not be converted. What should I check? =

Each failed file shows a reason on the Images screen. Settings > System information shows whether GD and Imagick can write WebP and AVIF on your server, and whether your uploads folder is writable. If neither library can write WebP, ask your host to enable WebP support in GD or Imagick. Then press "Convert existing images" again: only the images that still need it are processed.

= What is removed when I delete the plugin? =

All settings, rules and minified files, unless you turned off "Remove all PyCoreWeb Optimizer settings" on the Settings screen. WebP and AVIF copies are files and stay until you delete them from the Images screen.

= I used YU CoreOptimizer before. Are my rules kept? =

Yes. Site-wide and per-page unloading rules are imported the first time PyCoreWeb Optimizer is activated.

== Screenshots ==

1. Dashboard with the status of every feature and test mode.
2. Unload Files: every file a page loads, grouped by theme and plugin, with group rules.
3. CSS & JavaScript settings.
4. Images: lazy loading and WebP/AVIF conversion.

== External services ==

By default this plugin does not connect to any outside service. The file scan and cache preload load pages of your own site from your own server, and critical CSS is generated in your own browser. Two optional features, both off until you turn them on, use outside services:

* **Local Google Fonts** (More Speed > Local Google Fonts): when a page uses Google Fonts, your server downloads the font stylesheet from fonts.googleapis.com and the font files from fonts.gstatic.com once, and stores them in your uploads folder. Only the font address is sent, no visitor data. After that, visitors load the fonts from your own site. Google [Terms of Service](https://policies.google.com/terms), [Privacy Policy](https://policies.google.com/privacy).
* **Light video embeds** (More Speed > Light video embeds): YouTube preview images are loaded by the visitor's browser from i.ytimg.com, and the YouTube player loads only after the visitor clicks. For Vimeo videos, your server asks vimeo.com/api/oembed.json once for the preview image address of each video (only the video address is sent) and stores the answer. YouTube is a Google service: [Terms](https://www.youtube.com/t/terms), [Privacy Policy](https://policies.google.com/privacy). Vimeo: [Terms](https://vimeo.com/terms), [Privacy Policy](https://vimeo.com/privacy).

If you turn on "Preconnect to Google Fonts automatically", the plugin adds a preconnect hint for fonts.googleapis.com and fonts.gstatic.com, but only on pages that already load Google Fonts. The plugin itself sends no data to Google.

== Changelog ==

= 1.9.1 =
* New: screens can show extra sections (filter pyco_screen_sections), so add-ons extend the existing screens instead of adding their own.
* New: hooks pyco_dashboard_after, pyco_section_after, pyco_preset_card_after and pyco_preset_defaults.
* Changed: More Speed features always run here, also when an add-on is active.

= 1.9.0 =
* New: Page Cache. Static HTML pages served before the theme loads, phone copies, logged-in and cart bypass, automatic clearing on content changes, cache preload from the sitemap, optional Apache/LiteSpeed rules, admin bar clear buttons.
* New: one-click Recommended and Maximum setup on the Dashboard, tried in test mode first, with Undo.
* New: More Speed screen with hero image boost for Elementor (preload, WebP, phone size), below-the-fold rendering and lazy background images, instant page loads, local Google Fonts, light YouTube/Vimeo embeds, WordPress tweaks and Heartbeat control, and database cleanup.
* Delay all JavaScript: a tap or click made while scripts load is replayed when they are ready; also starts on the first touch; WooCommerce cart, checkout and account pages are never delayed; scripts marked nowprocket or data-no-delay and Google consent defaults run right away.
* When a page has a hero background image, the first image tags no longer compete with it for priority.
* With PyCoreWeb Optimizer Pro, features Pro also has stay off here while they are on in Pro, so nothing runs twice.

= 1.8.2 =
* Moving from the old "PyCore Optimizer" plugin is now fully in your hands: while the old plugin is active, PyCoreWeb Optimizer waits and asks you to deactivate it. It never switches other plugins on or off.
* Plugin, theme, upload and content folders are found with WordPress functions instead of WordPress constants.

= 1.8.1 =
* Page rewrites no longer leave an output buffer open. On WordPress 6.9 and later they use WordPress's own template output buffer whenever it is on; otherwise the theme template is wrapped, and the buffer is opened and closed in that one place. Sending the page head early still works.
* The Elementor reveal style is now added with wp_add_inline_style().
* No direct loading of WordPress core files for image conversion.

= 1.8.0 =
* New name: PyCore Optimizer is now PyCoreWeb Optimizer (folder and text domain pycoreweb-optimizer).
* Moving from the old plugin keeps every setting, and deleting the old plugin afterwards no longer removes them.

= 1.7.4 =
* The first images (the number set in "Skip the first images") are now also preloaded from the top of the page with high priority, so their download starts before the stylesheets. When the image is served as WebP or AVIF, that copy is preloaded. The page head is sent before the body is built, so the images found on the last visit of each address are used (option pyco_img_preload, filter pyco_preload_first_images).

= 1.7.3 =
* Add-ons can view a logged-in request as visitors see it (filter pyco_view_as_visitor), so page analysers see the same minified files as visitors even when "Do not apply these changes for logged-in users" is on.
* Minified copies remember their original file during the request, so other features can match them.

= 1.7.2 =
* The first images (the "Skip the first images" number) now also get fetchpriority="high", so the browser downloads them before other images. Images that already have a fetchpriority keep it.

= 1.7.1 =
* Fix: "Skip the first images" now also removes loading="lazy" that WordPress or a page builder (Elementor) added to those images, so the main image loads right away. "Never lazy-load" works the same way. Icons and images under 64 pixels are no longer counted.
* "Delay all JavaScript" has its own "load anyway after" timer, off by default. With the shared 10-second timer, scripts ran in the middle of PageSpeed's test, which never scrolls or taps, and hurt Speed Index.

= 1.7.0 =
* "Show text while fonts load" now also fixes fonts inside the site's own stylesheets (theme, page builder, Font Awesome as bundled by Elementor, which hides icons and text for up to 3 seconds) and in <style> blocks. Stylesheets with such fonts are served from a fixed copy in uploads/pycore-optimizer/min/; the originals are never changed.

= 1.6.0 =
* New: Delay all JavaScript. Every script on the page, inline ones too, waits for the first scroll, tap, click, mouse move or key press, then runs in its original order. Off by default; a "Never delay" list and a `data-pyco-nodelay` attribute keep chosen scripts running right away. With Elementor, animated sections are shown right away instead of staying hidden until the scripts run.
* The delay loader and the non-blocking CSS helper now load with defer, so they no longer block the page.
* Minified copies keep their names across plugin updates, so the Pro add-on's unused CSS analysis stays valid after updating.

= 1.5.0 =
* Faster first paint on slow-to-build pages (page builders such as Elementor, uncached pages): PyCoreWeb Optimizer used to hold the whole page until it was finished. It now sends the top of the page as soon as it is ready, so the browser starts loading CSS, fonts and scripts while the rest is still being built. All page rewrites share one buffer. Add `define( 'PYCO_NO_EARLY_FLUSH', true );` to wp-config.php to turn this off.
* New: Elementor-safe mode, on automatically when Elementor is active. jQuery, Elementor's scripts and everything they need are never delayed, because Elementor keeps animated sections hidden until its scripts run. On Elementor pages, CSS loads without blocking only once the page has its own critical CSS.

= 1.4.2 =
* Fixed: "The converted file was not written" when converting images on servers where Imagick cannot write WebP. Each file now tries Imagick and GD in turn, and the result is checked before it is kept.
* Fixed: PNG images with a limited colour palette now convert to WebP with GD, keeping transparency.
* Other plugins that change image output formats no longer interfere with WebP/AVIF copies.
* Gentler bulk conversion for shared hosting: one image per request with a short pause, and automatic retries after 5, 15 and 30 seconds when the server is busy.
* Clearer reasons for files that cannot be converted, and they are tried again on the next run.
* System information shows WebP and AVIF support for GD and Imagick separately, the memory limit and whether uploads are writable.

= 1.4.1 =
* Readme and plugin details prepared for WordPress.org.

= 1.4.0 =
* New: group rules on Unload Files. Use "Rules…" next to a file to unload it on page types, post types, categories, tags and other terms, page templates, logged-in or logged-out visitors, address patterns or WooCommerce pages, or to load it only on those pages.
* New: a list of every group rule, with one-click removal.
* Protected core files can't be given rules, and files other loaded files depend on keep loading, as before.

= 1.3.0 =
* New: Minify CSS and Minify JavaScript on the CSS & JavaScript screen, with an exclude list and a "Clear minified files" button. Both are off by default.
* Minified files are rebuilt automatically after settings changes, plugin or theme updates, and theme switches.

= 1.2.0 =
* New name: PyCoreWeb Optimizer.
* Unload Files, CSS & JavaScript and Images now live in one plugin with one menu, one test mode and one off switch.
* Critical CSS can be generated automatically in your own browser.
* No inline scripts: all JavaScript is loaded from files.
* All text is translatable.
* Deleting the plugin removes its settings.

= 1.1.0 =
* Safer unloading: exact handles only, protected core files, dependencies kept, front-end scan.

= 1.0.0 =
* First release as YU CoreOptimizer.

== Upgrade Notice ==

= 1.9.1 =
Small update for add-ons: they now show their settings inside the existing screens. Nothing changes on your site.

= 1.9.0 =
Adds a full page cache, one-click Recommended setup, hero image boost and more. Nothing changes until you turn the new features on. If you use another caching plugin, turn its page cache off before turning on Page Cache.

= 1.8.0 =
PyCore Optimizer is now PyCoreWeb Optimizer. Install and activate it, deactivate the old PyCore Optimizer, then delete the old plugin. Settings are kept.

= 1.7.0 =
Text and icons show right away while theme, page builder and Font Awesome fonts load.

= 1.6.0 =
New "Delay all JavaScript" option for the highest PageSpeed scores, with Elementor support.

= 1.5.0 =
Faster first paint on Elementor and other slow-to-build pages, and a new Elementor-safe mode.

= 1.4.2 =
Fixes image conversion errors on some hosts and makes bulk conversion gentler on shared hosting.

= 1.4.1 =
Readme and plugin details only. No changes to how the plugin works.

= 1.4.0 =
Adds group rules: unload files on page types, post types, categories, templates, visitors, addresses or WooCommerce pages.

= 1.3.0 =
Adds CSS and JavaScript minification (off by default).

= 1.2.0 =
Merges unloading, CSS & JavaScript and image optimization into one plugin. Rules from YU CoreOptimizer are imported automatically.
