Local CSS & JavaScript Minification, SRI & Relative URL Safety
Compress local stylesheets and classic scripts into kadicache-assets with automatic relative url() rewriting, SRI integrity preservation, and location-dependent script skips.
- Compresses local
.cssand.jsassets intowp-content/kadicache-assets/(CssOptimizer.php&JsOptimizer.php) without combining or reordering files, preserving HTTP/2 & HTTP/3 multiplexing. - Rewrites relative
url(../fonts/icon.woff2)and@importpaths inside minified stylesheets accurately so theme icons and backgrounds never404. - Enforces strict safety gates (
MAX_CSS / MAX_JS = 1 MB,MIN_SAVINGS = 32 bytes) and automatically skips Subresource Integrity (integrity="..."), ES modules (type="module"),nomodule, and location-dependent scripts (document.currentScript). - Includes built-in compatibility exclusions for external Elementor print stylesheets (
/elementor/css/) and PDF Embedder worker bundles (/pdf-embedder/js/).
Why KadiCache Minifies Individual Files Instead of Concatenating Giant Bundles#
A decade ago under HTTP/1.1, WordPress optimization plugins concatenated 20 separate CSS and JavaScript files into one giant merged-all.js file to work around browser 6-connection limits. On modern HTTP/2 and HTTP/3 (QUIC) servers, concatenating CSS/JS files is an anti-pattern that causes three serious problems:
- Cache Invalidation Amplification: Changing one 2 KB plugin script changes the combined hash of the entire
900 KBmega-bundle, forcing repeat visitors to re-download all 20 libraries! strict mode,import()& Global Scope Collisions: Concatenating a file starting with"use strict";ahead of legacy jQuery plugins—or merging scripts expecting their owndocument.currentScript.srcdirectory—triggersSyntaxErrorandTypeErrorcrashes.- Broken Media Queries &
@charset/@importRules: Naive CSS concatenation places@importrules below standard selectors where browsers ignore them.
KadiCache Free Core (CssOptimizer.php & JsOptimizer.php) minifies each eligible local stylesheet and classic script individually—stripping comments, whitespace, and formatting bloat while keeping exact <head> / <body> execution order and parallel HTTP/2–HTTP/3 streaming intact.
Inside CssOptimizer.php & JsOptimizer.php: Automatic Production Guardrails#
Both minifiers run behind HookFreeTagProcessor with deterministic safety boundaries so turning on Minify CSS files and Minify JavaScript files never breaks modern WordPress features:
| Safety Boundary | CssOptimizer.php (kadicache-assets/css/) | JsOptimizer.php (kadicache-assets/js/<scope>/) |
|---|---|---|
| File Size & Savings Gate | Max 1 MB (MAX_CSS), requires >= 32 B savings | Max 1 MB (MAX_JS), requires >= 32 B savings |
| Pre-Minified Detection | Skips files where minification saves < 32 bytes | Skips pre-minified bundles (*.min.js) saving CPU cycles |
Subresource Integrity (SRI) | Skips <link integrity="sha384-..."> automatically | Skips <script integrity="..."> & SRI-preloaded scripts |
| Modern Script / Link Types | Skips rel="alternate stylesheet" & disabled links | Skips ES type="module", nomodule, & consent-guarded tags |
| Relative Path & Location Safety | Rewrites relative url(...) paths to canonical origin/CDN | Detects document.currentScript / relative worker paths & skips (location-dependent) |
| CSP Header Validation | Verifies CspPolicy::allowsUrl('style', ...) | Verifies CspPolicy::allowsUrl('script', ...) |
| Built-In Plugin Defaults | Auto-excludes dynamic /elementor/css/ external files | Auto-excludes /pdf-embedder/js/ worker directories |
| Commerce Checkout Protection | Automatically bypasses is_cart(), is_checkout(), is_account_page() | Automatically bypasses is_cart(), is_checkout(), is_account_page() |
Notice why KadiCache stores generated assets under wp-content/kadicache-assets/ rather than inside wp-content/cache/kadicache/: KadiCache’s private HTML page-cache storage uses hardened 0700 directory permissions so nobody can browse raw cache directories over HTTP, whereas kadicache-assets/ is a clean, publicly web-servable static directory compatible with Nginx, Apache, and pull-zone CDNs (CdnUrlRewriter.php).
Configuring Local Minify Exclusions & Developer Attributes#
Inside WP Admin -> KadiCache -> CSS & JavaScript, you have four granular ways to exclude any file or page from minification:
- Excluded CSS Files (
minify_css_exclusions) & Excluded CSS Page Paths (minify_css_excluded_paths): Expand the drawers at the bottom of the CSS Delivery card and enter filename fragments (custom-legacy-grid.css) or URL path prefixes (/legacy-embed/*). - Excluded JS Files (
minify_js_exclusions) & Excluded JS Page Paths (minify_js_excluded_paths): Expand the drawers inside JavaScript Execution & Minification to skip specific.jspaths. - HTML Attribute Opt-Out (
data-no-minify): Adddata-no-minifyto any<link rel="stylesheet">or<script>tag in custom theme PHP code. - WordPress PHP Filters (
kadicache_minify_css_exclusions/kadicache_minify_js_exclusions): Register plugin-level exclusions programmatically when distributing a custom agency theme:
add_filter('kadicache_minify_css_exclusions', static function (array $exclusions): array {
$exclusions[] = '/themes/agency-child/assets/css/print-invoice.css';
return $exclusions;
});
add_filter('kadicache_minify_js_exclusions', static function (array $exclusions): array {
$exclusions[] = '/plugins/bespoke-webgl-viewer/dist/';
return $exclusions;
});CDN Compatibility, Cache Busting & Disk Hygiene for kadicache-assets#
Understanding how KadiCache manages wp-content/kadicache-assets/ helps DevOps engineers configure Nginx, Apache, and CDN edge rules cleanly:
- Automatic Version & Content Fingerprinting: Whenever a plugin or theme updates a source
.cssor.jsfile, KadiCache computes a fresh content-addressed filename automatically—so browsers and CDNs fetch the updated file immediately without serving stale assets, even whenCache-Control: public, max-age=31536000, immutableis active! - Multisite & Multilingual Domain Scoping:
CssOptimizer.phpandJsOptimizer.phpscope generated asset URLs per site and active language domain (LanguageDomains::currentOriginUrl()) so cross-domain multilingual networks never encounter CORS mismatches. - Safe Cleanup on Purge & Uninstall:
CacheMaintenance.phpandUninstallFilesystem.phpprune retired generated assets cleanly without ever touchingwp-content/uploads/or theme source directories.
Frequently Asked Operational Questions
Why doesn’t KadiCache combine all CSS or all JS files into one single file?
Will Minify CSS break relative font or background icon URLs like url(../webfonts/fa-solid-900.woff2)?
Why does CssOptimizer exclude /elementor/css/ automatically when Elementor uses external print files?
Does KadiCache re-minify files on every visitor request?
Can I disable minification on just one page without editing global file exclusions?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.