includes/minify/class-html.php
Handles HTML, CSS, and JS minification for improved website performance.
Class HTML
Class HTML
class HTMLProperties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$html_min | private | ?HtmlMin | null | 47 |
$html_min_base_url | private | string | \'\' | 58 |
$preserve_namespace | private | string | \'\' | 70 |
$minified_html | private | string | — | 78 |
$options | private | array | — | 86 |
$exclude_delay_js | private | array | — | 94 |
$delay_exclude_re | private | ?string | null | 112 |
$delay_idle_re | private | ?string | null | 123 |
$delay_viewport_re | private | ?string | null | 131 |
$delay_priority_re | private | ?string | null | 142 |
$delay_js_idle_list | private | array | array() | 150 |
$delay_js_viewport_list | private | array | array() | 158 |
$delay_js_default_strategy | private | string | \'interaction\' | 166 |
$delay_js_priority | private | array | array() | 174 |
public __construct()
public function __construct($html, $options)Constructor to initialize HTML minification. Parameter Type Default Description $htmlstring— The HTML content to minify. $optionsarray— Minification options.
privatestatic compile_delay_exclude_re()
private static function compile_delay_exclude_re(array $exclusions): ?stringCompile a case-insensitive substring alternation for delay exclusions. Parameter Type Default Description $exclusionsarray— Exclusion fragments.
Return: string|null — Ready regex, or null when unusable.
privatestatic third_party_settings_key()
private static function third_party_settings_key($allow_raw, $extra_raw): ?stringBuild a per-request cache key for third-party allow/deny settings. Parameter Type Default Description $allow_rawmixed— Allowlist raw setting value. $extra_rawmixed— Denylist raw setting value.
Return: string|null — Cache key.
private initialize_minification_settings()
private function initialize_minification_settings(): voidInitialize minification settings.
Return: void.
private get_html_min()
private function get_html_min(): HtmlMinGet (and lazily configure) the HtmlMin instance.
Return: HtmlMin.
private minify_html()
private function minify_html(string $html): stringMinify HTML content. Parameter Type Default Description $htmlstring— The HTML content to minify.
Return: string — Minified HTML content.
private get_preserve_namespace()
private function get_preserve_namespace(): stringGet (and lazily mint) the per-request preserve namespace.
Return: string — Non-empty namespace string.
private resolve_preserved_script()
private function resolve_preserved_script(string $token, array $scripts): ?stringResolve a single preserved-script placeholder token against the allowlist. Parameter Type Default Description $tokenstring— The matched placeholder tag. $scriptsarray— The preserved scripts allowlist.
Return: string|null — Restored script HTML, or null on anomaly.
private get_script_type()
private function get_script_type(string $attributes): stringExtract the script type from attributes string. Parameter Type Default Description $attributesstring— The script attributes string.
Return: string — The extracted and lowercased script type, or an empty string.
private modify_canonical_link()
private function modify_canonical_link(string $html): ?stringModify the canonical link in HTML. Parameter Type Default Description $htmlstring— The HTML content.
Return: string — Modified HTML content.
private extract_and_preserve_scripts_template()
private function extract_and_preserve_scripts_template($html)Extract and preserve script tags for later restoration. Parameter Type Default Description $htmlstring— The HTML content.
Return: array — Updated HTML and preserved script tags.
private restore_preserved_scripts_template()
private function restore_preserved_scripts_template($html, $scripts)Restore preserved script tags in HTML. Parameter Type Default Description $htmlstring— The HTML content. $scriptsarray— The preserved scripts.
Return: string — Updated HTML content.
private restore_canonical_link()
private function restore_canonical_link(string $html): stringRestore the canonical link in HTML. Parameter Type Default Description $htmlstring— The HTML content.
Return: string — HTML content with the canonical link restored.
private safe_minify_css_block()
private function safe_minify_css_block(string $attrs, string $css): stringMinify a single inline CSS block with a fail-open contract. Parameter Type Default Description $attrsstring— Style tag attributes string (including leading space). $cssstring— Raw CSS block content.
Return: string — Minified style tag, or the pristine tag on failure.
private minify_inline_css()
private function minify_inline_css(string $html): stringMinify inline CSS in HTML. Parameter Type Default Description $htmlstring— The HTML content containing inline CSS.
Return: string — HTML content with minified CSS.
private minify_inline_js()
private function minify_inline_js(string $html): stringMinify inline JavaScript in HTML. Parameter Type Default Description $htmlstring— The HTML content containing inline JS.
Return: string — HTML content with minified JS.
private safe_minify_js()
private function safe_minify_js(string $attributes, string $content): stringMinify inline JavaScript safely. Parameter Type Default Description $attributesstring— The script attributes. $contentstring— The JavaScript content to minify.
Return: string — Minified JS or original content if error occurs.
private preserve_json_ld()
private function preserve_json_ld(string $content, string $attributes): stringPreserve JSON-LD content by passing it through. Parameter Type Default Description $contentstring— The JSON-LD content. $attributesstring— The script attributes.
Return: string — Original script tag with content.
private get_delay_strategy_for_inline()
private function get_delay_strategy_for_inline(string $attributes, string $content, array=array() $file_opt, ?bool=null $is_auto_matched): stringDetermine delay strategy for an inline script. Parameter Type Default Description $attributesstring— Script tag attributes string. $contentstring— Inline script content. $file_optarray=array()— Optional effective file_optimisation slice (preview-aware). $is_auto_matched?bool=null— Optional precomputed auto-candidate verdict.
Return: string — Strategy: \’interaction\’, \’idle\’, or \’viewport\’.
private get_delay_priority_for_inline()
private function get_delay_priority_for_inline(string $attributes, string $content): stringDetermine delay priority for an inline script. Parameter Type Default Description $attributesstring— Script tag attributes string. $contentstring— Inline script content.
Return: string — Priority: \’high\’, \’normal\’, or \’low\’.
privatestatic is_localised_inline_script()
private static function is_localised_inline_script(string $attributes, string $content): boolWhether an inline script is a localised/config payload (issue #1055). Parameter Type Default Description $attributesstring— Script tag attributes string. $contentstring— Inline script content.
Return: bool — True when the script must stay un-delayed.
privatestatic is_delay_excluded_context()
private static function is_delay_excluded_context(): boolWhether the current request must skip delay-JS rewriting.
Return: bool — True when delay must be skipped for this request.
privatestatic is_third_party_delay_candidate()
private static function is_third_party_delay_candidate(string $attributes, string $content, array $file_opt): boolWhether an inline-path script is a third-party delay candidate (#1217). Parameter Type Default Description $attributesstring— Script attributes string. $contentstring— Inline script content. $file_optarray— Effective file_optimisation slice.
Return: bool — True when the script should be delayed.
privatestatic markup_matches_third_party_auto_patterns()
private static function markup_matches_third_party_auto_patterns(string $attributes, string $content): boolWhether markup matches the curated auto third-party patterns (#1314). Parameter Type Default Description $attributesstring— Script attributes string. $contentstring— Inline script content (ignored; kept for signature parity).
Return: bool — True on match.
privatestatic is_third_party_auto_delay_candidate()
private static function is_third_party_auto_delay_candidate(string $attributes, string $content, array $file_opt): boolWhether buffered-path markup is an auto third-party delay candidate (#1314). Parameter Type Default Description $attributesstring— Script attributes string. $contentstring— Inline script content (ignored except for signature parity). $file_optarray— Effective file_optimisation slice.
Return: bool — True when the script should be delayed in auto mode.
public get_minified_html()
public function get_minified_html(): stringGet the minified HTML content.
Return: string — Minified HTML content.
Hooks
Hooks referenced in includes/minify/class-html.php: Hook Type Line Notes wppo_exclude_delay_jsfilter 309 — wppo_debug_logaction 606 — wppo_delay_js_third_party_allowlistfilter 1441 — wppo_delay_js_third_party_allowlistfilter 1665 —