class-html.php

Handles HTML, CSS, and JS minification for improved website performance.

Source includes/minify/class-html.php6 min readPart of Performance Optimisation

includes/minify/class-html.php

Handles HTML, CSS, and JS minification for improved website performance.

Namespace: PerformanceOptimise\\Inc\\Minify · Lines: 1704

Class HTML

Class HTML

Source: includes/minify/class-html.php, line 35

class HTML

Tags: @since 1.0.0

Properties

PropertyVisibilityTypeDefaultLine
$html_minprivate?HtmlMinnull47
$html_min_base_urlprivatestring\'\'58
$preserve_namespaceprivatestring\'\'70
$minified_htmlprivatestring—78
$optionsprivatearray—86
$exclude_delay_jsprivatearray—94
$delay_exclude_reprivate?stringnull112
$delay_idle_reprivate?stringnull123
$delay_viewport_reprivate?stringnull131
$delay_priority_reprivate?stringnull142
$delay_js_idle_listprivatearrayarray()150
$delay_js_viewport_listprivatearrayarray()158
$delay_js_default_strategyprivatestring\'interaction\'166
$delay_js_priorityprivatearrayarray()174

public __construct()

public function __construct($html, $options)

Constructor to initialize HTML minification.

ParameterTypeDefaultDescription
$htmlstring—The HTML content to minify.
$optionsarray—Minification options.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 183

privatestatic compile_delay_exclude_re()

private static function compile_delay_exclude_re(array $exclusions): ?string

Compile a case-insensitive substring alternation for delay exclusions.

ParameterTypeDefaultDescription
$exclusionsarray—Exclusion fragments.

Return: string|null — Ready regex, or null when unusable.

Tags: @since 2.2.0

Source: includes/minify/class-html.php, line 434

privatestatic third_party_settings_key()

private static function third_party_settings_key($allow_raw, $extra_raw): ?string

Build a per-request cache key for third-party allow/deny settings.

ParameterTypeDefaultDescription
$allow_rawmixed—Allowlist raw setting value.
$extra_rawmixed—Denylist raw setting value.

Return: string|null — Cache key.

Tags: @since 2.2.0

Source: includes/minify/class-html.php, line 482

private initialize_minification_settings()

private function initialize_minification_settings(): void

Initialize minification settings.

Return: void.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 513

private get_html_min()

private function get_html_min(): HtmlMin

Get (and lazily configure) the HtmlMin instance.

Return: HtmlMin.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 546

private minify_html()

private function minify_html(string $html): string

Minify HTML content.

ParameterTypeDefaultDescription
$htmlstring—The HTML content to minify.

Return: string — Minified HTML content.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 587

private get_preserve_namespace()

private function get_preserve_namespace(): string

Get (and lazily mint) the per-request preserve namespace.

Return: string — Non-empty namespace string.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 630

private resolve_preserved_script()

private function resolve_preserved_script(string $token, array $scripts): ?string

Resolve a single preserved-script placeholder token against the allowlist.

ParameterTypeDefaultDescription
$tokenstring—The matched placeholder tag.
$scriptsarray—The preserved scripts allowlist.

Return: string|null — Restored script HTML, or null on anomaly.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 653

private get_script_type()

private function get_script_type(string $attributes): string

Extract the script type from attributes string.

ParameterTypeDefaultDescription
$attributesstring—The script attributes string.

Return: string — The extracted and lowercased script type, or an empty string.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 701

private function modify_canonical_link(string $html): ?string

Modify the canonical link in HTML.

ParameterTypeDefaultDescription
$htmlstring—The HTML content.

Return: string — Modified HTML content.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 720

private extract_and_preserve_scripts_template()

private function extract_and_preserve_scripts_template($html)

Extract and preserve script tags for later restoration.

ParameterTypeDefaultDescription
$htmlstring—The HTML content.

Return: array — Updated HTML and preserved script tags.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 739

private restore_preserved_scripts_template()

private function restore_preserved_scripts_template($html, $scripts)

Restore preserved script tags in HTML.

ParameterTypeDefaultDescription
$htmlstring—The HTML content.
$scriptsarray—The preserved scripts.

Return: string — Updated HTML content.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 782

private function restore_canonical_link(string $html): string

Restore the canonical link in HTML.

ParameterTypeDefaultDescription
$htmlstring—The HTML content.

Return: string — HTML content with the canonical link restored.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 809

private safe_minify_css_block()

private function safe_minify_css_block(string $attrs, string $css): string

Minify a single inline CSS block with a fail-open contract.

ParameterTypeDefaultDescription
$attrsstring—Style tag attributes string (including leading space).
$cssstring—Raw CSS block content.

Return: string — Minified style tag, or the pristine tag on failure.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 837

private minify_inline_css()

private function minify_inline_css(string $html): string

Minify inline CSS in HTML.

ParameterTypeDefaultDescription
$htmlstring—The HTML content containing inline CSS.

Return: string — HTML content with minified CSS.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 859

private minify_inline_js()

private function minify_inline_js(string $html): string

Minify inline JavaScript in HTML.

ParameterTypeDefaultDescription
$htmlstring—The HTML content containing inline JS.

Return: string — HTML content with minified JS.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 881

private safe_minify_js()

private function safe_minify_js(string $attributes, string $content): string

Minify inline JavaScript safely.

ParameterTypeDefaultDescription
$attributesstring—The script attributes.
$contentstring—The JavaScript content to minify.

Return: string — Minified JS or original content if error occurs.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 901

private preserve_json_ld()

private function preserve_json_ld(string $content, string $attributes): string

Preserve JSON-LD content by passing it through.

ParameterTypeDefaultDescription
$contentstring—The JSON-LD content.
$attributesstring—The script attributes.

Return: string — Original script tag with content.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 1167

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): string

Determine delay strategy for an inline script.

ParameterTypeDefaultDescription
$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\’.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 1195

private get_delay_priority_for_inline()

private function get_delay_priority_for_inline(string $attributes, string $content): string

Determine delay priority for an inline script.

ParameterTypeDefaultDescription
$attributesstring—Script tag attributes string.
$contentstring—Inline script content.

Return: string — Priority: \’high\’, \’normal\’, or \’low\’.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 1282

privatestatic is_localised_inline_script()

private static function is_localised_inline_script(string $attributes, string $content): bool

Whether an inline script is a localised/config payload (issue #1055).

ParameterTypeDefaultDescription
$attributesstring—Script tag attributes string.
$contentstring—Inline script content.

Return: bool — True when the script must stay un-delayed.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 1323

privatestatic is_delay_excluded_context()

private static function is_delay_excluded_context(): bool

Whether the current request must skip delay-JS rewriting.

Return: bool — True when delay must be skipped for this request.

Tags: @since 2.0.0

Source: includes/minify/class-html.php, line 1351

privatestatic is_third_party_delay_candidate()

private static function is_third_party_delay_candidate(string $attributes, string $content, array $file_opt): bool

Whether an inline-path script is a third-party delay candidate (#1217).

ParameterTypeDefaultDescription
$attributesstring—Script attributes string.
$contentstring—Inline script content.
$file_optarray—Effective file_optimisation slice.

Return: bool — True when the script should be delayed.

Tags: @since 2.2.0

Source: includes/minify/class-html.php, line 1381

privatestatic markup_matches_third_party_auto_patterns()

private static function markup_matches_third_party_auto_patterns(string $attributes, string $content): bool

Whether markup matches the curated auto third-party patterns (#1314).

ParameterTypeDefaultDescription
$attributesstring—Script attributes string.
$contentstring—Inline script content (ignored; kept for signature parity).

Return: bool — True on match.

Tags: @since 2.2.0

Source: includes/minify/class-html.php, line 1558

privatestatic is_third_party_auto_delay_candidate()

private static function is_third_party_auto_delay_candidate(string $attributes, string $content, array $file_opt): bool

Whether buffered-path markup is an auto third-party delay candidate (#1314).

ParameterTypeDefaultDescription
$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.

Tags: @since 2.2.0

Source: includes/minify/class-html.php, line 1623

public get_minified_html()

public function get_minified_html(): string

Get the minified HTML content.

Return: string — Minified HTML content.

Tags: @since 1.0.0

Source: includes/minify/class-html.php, line 1700

Hooks

Hooks referenced in includes/minify/class-html.php:

HookTypeLineNotes
wppo_exclude_delay_jsfilter309—
wppo_debug_logaction606—
wppo_delay_js_third_party_allowlistfilter1441—
wppo_delay_js_third_party_allowlistfilter1665—