includes/Assets/class-script-strategy.php
Script loading strategy — defer rendering + delay-JS decisions and data.
Class Script_Strategy
Class Script_Strategy
final class Script_StrategyProperties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$main | private | Main | — | 67 |
$delay_pattern_regex_cache | private static | array | array() | 92 |
$delay_excluded_context_memo | private static | ?bool | null | 106 |
$delay_excluded_context_memo_sig | private static | string | \'\' | 114 |
$delay_js_third_party_auto_cache | private static | ?array | null | 126 |
$delay_js_third_party_auto_cache_blog | private static | int | 0 | 138 |
$delay_js_third_party_auto_handle_segments | private static | array | array() | 150 |
$delay_js_third_party_auto_handle_re | private static | string | \'\' | 158 |
$delay_js_third_party_auto_handle_key | private static | ?string | null | 168 |
$delay_js_auto_label_commerce | private static | ?array | null | 183 |
$delay_js_auto_label_categories | private static | ?array | null | 193 |
$delay_js_auto_label_blog | private static | int | 0 | 201 |
public __construct()
public function __construct(Main $main)Constructor. Parameter Type Default Description $mainMain— Main instance (hook-state + settings owner).
public remove_woocommerce_scripts()
public function remove_woocommerce_scripts()Dequeues configured WooCommerce CSS and JS handles unless the current URL is excluded.
publicstatic supports_native_defer_strategy()
public static function supports_native_defer_strategy(): boolWhether the native WP 6.3+ script loading strategy API can be used.
Return: bool — True when the native defer strategy path is allowed. Relocated from Main::supports_native_defer_strategy() (ARCH-005).
publicstatic supports_native_script_fetchpriority()
public static function supports_native_script_fetchpriority(): boolWhether the native WP 6.9+ script fetchpriority API can be used.
Return: bool — True when the native fetchpriority path is allowed. Relocated from Main::supports_native_script_fetchpriority() (ARCH-005).
public is_defer_eligible_for_handle()
public function is_defer_eligible_for_handle(object $wp_scripts, string $handle, array=array() $intended, array&=array() $checked): boolWhether a queued handle is eligible for a deferred loading strategy. Parameter Type Default Description $wp_scriptsobject— WP_Scripts registry. $handlestring— Script handle. $intendedarray=array()— Handles this run intends to defer (pass the interactivity guard and exclusion list). Defaults to empty for direct calls. $checkedarray&=array()— Visited handles for the recursion guard (mirrors core\’s $checked). Callers leave this at its default; a fresh map is used per top-level evaluation.
Return: bool — True when the handle may receive strategy defer. Relocated from Main::is_defer_eligible_for_handle() (ARCH-005).
publicstatic should_use_core_template_buffer()
public static function should_use_core_template_buffer(): boolWhether the WP 6.9+ core template-enhancement buffer should carry plugin post-processing.
Return: bool — True when the core template-enhancement buffer path is allowed. Relocated to Preload_Buffer_Coordinator in P3-015; retained as a compatibility proxy for existing Script_Strategy callers.
public get_filtered_deferred_fetchpriority()
public function get_filtered_deferred_fetchpriority(string $handle): stringResolve the filtered fetchpriority for a deferred handle. Parameter Type Default Description $handlestring— Script handle or module id.
Return: string — Validated \’high\’|\’low\’|\’auto\’, or \’\’ to suppress. Relocated from Main::get_filtered_deferred_fetchpriority() (ARCH-005).
public should_move_deferred_to_footer()
public function should_move_deferred_to_footer(string $handle): boolWhether a deferred handle should be moved to the footer. Parameter Type Default Description $handlestring— Script handle or module id.
Return: bool — True when the handle should be footer-bound. Relocated from Main::should_move_deferred_to_footer() (ARCH-005).
public add_defer_strategy()
public function add_defer_strategy(): voidApplies defer strategy to non-logged-in users\’ scripts using wp_script_add_data.
Return: void — Relocated from Main::add_defer_strategy() (ARCH-005).
public is_executable_script_type()
public function is_executable_script_type(string $tag): boolWhether a script tag\’s type attribute is executable JavaScript. Parameter Type Default Description $tagstring— The script tag markup.
Return: bool — True when the tag may be delay-rewritten. Relocated from Main::is_executable_script_type() (ARCH-005).
public add_defer_attribute()
public function add_defer_attribute($tag, $handle): stringAdds defer attribute to non-logged-in users\’ scripts. Parameter Type Default Description $tagstring— The script tag HTML. $handlestring— The script\’s registered handle.
Return: string — Modified script tag with defer attribute. Relocated from Main::add_defer_attribute() (ARCH-005).
public add_defer_attribute_legacy()
public function add_defer_attribute_legacy($tag, $handle): stringAdds the defer attribute to script tags on WordPress < 6.3. Parameter Type Default Description $tagstring— The script tag HTML. $handlestring— The script\’s registered handle.
Return: string — Modified script tag with the defer attribute. Relocated from Main::add_defer_attribute_legacy() (ARCH-005).
public matches_delay_pattern()
public function matches_delay_pattern(string $handle, string $pattern): boolCheck whether a script handle matches a delay pattern using word boundaries. Parameter Type Default Description $handlestring— The script handle. $patternstring— The configured pattern (handle or URL).
Return: bool — True if the handle matches the pattern. Relocated from Main::matches_delay_pattern() (ARCH-005).
privatestatic get_delay_patterns_regex()
private static function get_delay_patterns_regex(array $patterns): stringBuild (once per request) a combined alternation regex for a pattern list. Parameter Type Default Description $patternsarray— Pattern list.
Return: string — Empty string when no usable patterns; otherwise a ready regex. Relocated from Main::get_delay_patterns_regex() (ARCH-005).
public matches_any_delay_pattern()
public function matches_any_delay_pattern(string $handle, array $patterns): boolWhether a handle matches any pattern in a list via the precompiled alternation. Parameter Type Default Description $handlestring— Script handle. $patternsarray— Pattern list.
Return: bool — True on match. Relocated from Main::matches_any_delay_pattern() (ARCH-005).
public is_delay_excluded_handle()
public function is_delay_excluded_handle(string $handle): boolWhether a script handle is excluded from Delay JS. Parameter Type Default Description $handlestring— The script\’s registered handle.
Return: bool — True when the handle must stay un-delayed. Relocated from Main::is_delay_excluded_handle() (ARCH-005).
public get_delay_exclusions()
public function get_delay_exclusions(): arrayDelay-JS exclusions with `wppo_exclude_delay_js` applied on first use.
Return: array<int, — string> Relocated from Main::get_delay_exclusions() (ARCH-005).
publicstatic is_delay_excluded_context()
public 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. Relocated from Main::is_delay_excluded_context() (ARCH-005).
privatestatic delay_context_request_signature()
private static function delay_context_request_signature(): stringSignature of the request inputs that drive the delay-context verdict.
Return: string — Signature string. Relocated from Main::delay_context_request_signature() (ARCH-005).
publicstatic reset_delay_context_memo()
public static function reset_delay_context_memo(): voidReset the per-request delay-context memo (for tests).
Return: void — Relocated from Main::reset_delay_context_memo() (ARCH-005).
privatestatic compute_delay_excluded_context()
private static function compute_delay_excluded_context(): boolCompute whether the current request must skip delay-JS rewriting.
Return: bool — True when delay must be skipped for this request. Relocated from Main::compute_delay_excluded_context() (ARCH-005).
privatestatic matches_woo_page_path()
private static function matches_woo_page_path(string $local_path): boolWhether a request path belongs to a WooCommerce cart/checkout/account page. Parameter Type Default Description $local_pathstring— Request path with a leading slash.
Return: bool — True when the path is a Woo page path. Relocated from Main::matches_woo_page_path() (ARCH-005).
public get_delay_strategy_for_handle()
public function get_delay_strategy_for_handle(string $handle, string=\'\' $tag, ?bool=null $is_auto_matched): stringGet the delay strategy for a given script handle. Parameter Type Default Description $handlestring— The script handle. $tagstring=\'\'— Optional script tag markup (for auto-mode src matching). $is_auto_matched?bool=null— Optional precomputed auto-candidate verdict.
Return: string — The strategy: \’interaction\’, \’idle\’, or \’viewport\’. Relocated from Main::get_delay_strategy_for_handle() (ARCH-005).
public get_delay_priority_for_handle()
public function get_delay_priority_for_handle(string $handle): stringGet the delay priority for a given script handle. Parameter Type Default Description $handlestring— The script handle.
Return: string — The priority: \’high\’, \’normal\’, or \’low\’. Relocated from Main::get_delay_priority_for_handle() (ARCH-005).
public apply_per_page_delay_config()
public function apply_per_page_delay_config(): voidApply per-page delay configuration overrides from the Asset Manager metabox.
Return: void — Relocated from Main::apply_per_page_delay_config() (ARCH-005).
publicstatic get_delay_js_builder_exclusions()
public static function get_delay_js_builder_exclusions(): arrayCurated per-builder Delay JS exclusions (issue #966).
Return: string[] — Relocated from Main::get_delay_js_builder_exclusions() (ARCH-005).
publicstatic get_delay_js_commerce_exclusions()
public static function get_delay_js_commerce_exclusions(): arrayCurated commerce Delay JS exclusions (issue #988).
Return: string[] — Relocated from Main::get_delay_js_commerce_exclusions() (ARCH-005).
publicstatic get_delay_js_slider_exclusions()
public static function get_delay_js_slider_exclusions(): arrayCurated slider Delay JS exclusions (issue #988).
Return: string[] — Relocated from Main::get_delay_js_slider_exclusions() (ARCH-005).
publicstatic get_delay_js_interaction_exclusions()
public static function get_delay_js_interaction_exclusions(): arrayCurated first-click interaction Delay JS exclusions (issue #1055).
Return: string[] — Relocated from Main::get_delay_js_interaction_exclusions() (ARCH-005).
publicstatic get_delay_js_preset_levels()
public static function get_delay_js_preset_levels(): arrayOne-click Delay-JS preset levels (issue #1385).
Return: string[] — Relocated from Main::get_delay_js_preset_levels() (ARCH-005).
publicstatic get_delay_js_preset_level_settings()
public static function get_delay_js_preset_level_settings(string $level): arrayToggle map applied by a one-click Delay-JS preset level (issue #1385). Parameter Type Default Description $levelstring— Preset level (safe|balanced|aggressive).
Return: array<string, — bool> Relocated from Main::get_delay_js_preset_level_settings() (ARCH-005).
publicstatic get_delay_js_preset_level_exclusions()
public static function get_delay_js_preset_level_exclusions(string $level): arrayMerged exclusion list for a one-click Delay-JS preset level (issue #1385). Parameter Type Default Description $levelstring— Preset level (safe|balanced|aggressive).
Return: string[] — Relocated from Main::get_delay_js_preset_level_exclusions() (ARCH-005).
privatestatic filter_compat_preset_list()
private static function filter_compat_preset_list(string $filter, array $preset): arrayApply a preset exclusion filter with fail-open guards (issue #1308). Parameter Type Default Description $filterstring— Filter hook name. $presetarray— Curated preset exclusions.
Return: string[] — Relocated from Main::filter_compat_preset_list() (ARCH-005).
publicstatic get_delay_js_consent_exclusions()
public static function get_delay_js_consent_exclusions(): arrayCurated consent Delay JS exclusions (issue #1308).
Return: string[] — Relocated from Main::get_delay_js_consent_exclusions() (ARCH-005).
publicstatic get_delay_js_analytics_exclusions()
public static function get_delay_js_analytics_exclusions(): arrayCurated analytics Delay JS exclusions (issue #1308).
Return: string[] — Relocated from Main::get_delay_js_analytics_exclusions() (ARCH-005).
publicstatic get_delay_js_gallery_exclusions()
public static function get_delay_js_gallery_exclusions(): arrayCurated gallery Delay JS exclusions (issue #1308).
Return: string[] — Relocated from Main::get_delay_js_gallery_exclusions() (ARCH-005).
publicstatic get_delay_js_jquery_exclusions()
public static function get_delay_js_jquery_exclusions(): arrayCurated jQuery-legacy Delay JS exclusions (issue #1308).
Return: string[] — Relocated from Main::get_delay_js_jquery_exclusions() (ARCH-005).
publicstatic get_delay_js_compat_preset_map()
public static function get_delay_js_compat_preset_map(): arrayCompat preset slugs keyed by their settings key (issue #1308).
Return: array<string, — string> Relocated from Main::get_delay_js_compat_preset_map() (ARCH-005).
publicstatic get_delay_js_compat_preset_exclusions()
public static function get_delay_js_compat_preset_exclusions(string $slug): arrayExclusion list for one compat preset slug (issue #1308). Parameter Type Default Description $slugstring— Preset slug (consent|analytics|gallery|jquery).
Return: string[] — Relocated from Main::get_delay_js_compat_preset_exclusions() (ARCH-005).
publicstatic get_delay_js_third_party_denylist()
public static function get_delay_js_third_party_denylist(): arrayCurated third-party Delay-JS denylist (one-click delay, issue #1217).
Return: string[] — Relocated from Main::get_delay_js_third_party_denylist() (ARCH-005).
publicstatic get_delay_js_third_party_allowlist_for_slice()
public static function get_delay_js_third_party_allowlist_for_slice(array $file_opt): arrayParse the user-configured third-party allowlist for a settings slice. Parameter Type Default Description $file_optarray— Effective file_optimisation slice.
Return: string[] — Relocated from Main::get_delay_js_third_party_allowlist_for_slice() (ARCH-005).
public get_delay_js_third_party_allowlist()
public function get_delay_js_third_party_allowlist(): arrayParse the user-configured third-party allowlist (wins over denylist).
Return: string[] — Relocated from Main::get_delay_js_third_party_allowlist() (ARCH-005).
public is_delay_third_party_candidate()
public function is_delay_third_party_candidate(string $tag, string $handle): boolWhether a script tag/handle is a third-party delay candidate. Parameter Type Default Description $tagstring— Script tag markup. $handlestring— Script handle.
Return: bool — True when the script should be delayed in third-party mode. Relocated from Main::is_delay_third_party_candidate() (ARCH-005).
publicstatic is_same_site_script_host()
public static function is_same_site_script_host(string $a, string $b): boolWhether two script hosts belong to the same site (issue #1217 review). Parameter Type Default Description $astring— First host. $bstring— Second host.
Return: bool — True when both hosts belong to the same site. Relocated from Main::is_same_site_script_host() (ARCH-005).
publicstatic get_delay_js_third_party_auto_categories()
public static function get_delay_js_third_party_auto_categories(): arrayLabelled auto third-party vendor categories (issue #1385).
Return: array<string, — string[]> Relocated from Main::get_delay_js_third_party_auto_categories() (ARCH-005).
publicstatic get_delay_js_third_party_auto_label()
public static function get_delay_js_third_party_auto_label(string $src_or_handle): stringLabel a script src/handle with its auto third-party category (issue #1385). Parameter Type Default Description $src_or_handlestring— Script src URL, tag markup, or handle.
Return: string — Category label or empty string. Relocated from Main::get_delay_js_third_party_auto_label() (ARCH-005).
publicstatic reset_delay_third_party_auto_cache()
public static function reset_delay_third_party_auto_cache(): voidReset the auto third-party pattern memo (for tests).
Return: void — Relocated from Main::reset_delay_third_party_auto_cache() (ARCH-005).
publicstatic get_delay_js_third_party_auto_patterns()
public static function get_delay_js_third_party_auto_patterns(): arrayCurated known-vendor URL patterns for auto third-party delay (#1314).
Return: string[] — Relocated from Main::get_delay_js_third_party_auto_patterns() (ARCH-005).
publicstatic matches_third_party_auto_pattern()
public static function matches_third_party_auto_pattern(string $handle, string $tag): boolWhether a handle/tag matches the curated auto third-party patterns (#1314). Parameter Type Default Description $handlestring— Script handle (may be empty on buffered paths). $tagstring— Script tag markup or src URL.
Return: bool — True on match. Relocated from Main::matches_third_party_auto_pattern() (ARCH-005).
public is_delay_third_party_auto_candidate()
public function is_delay_third_party_auto_candidate(string $tag, string $handle): boolWhether a script tag/handle is an auto third-party delay candidate (#1314). Parameter Type Default Description $tagstring— Script tag markup. $handlestring— Script handle.
Return: bool — True when the script should be delayed in auto mode. Relocated from Main::is_delay_third_party_auto_candidate() (ARCH-005).
privatestatic inject_delay_script_attr()
private static function inject_delay_script_attr(string $tag, string $insert): stringInject an attribute string into a script open tag (issue #1217 review). Parameter Type Default Description $tagstring— Script tag markup. $insertstring— Attribute string including trailing space, e.g. \’fetchpriority=\”low\” \’.
Return: string — Tag with the attributes injected. Relocated from Main::inject_delay_script_attr() (ARCH-005).
publicstatic get_delay_js_base_preset_exclusions()
public static function get_delay_js_base_preset_exclusions(): arrayBase Delay JS preset exclusions (always applied, issue #966).
Return: string[] — Relocated from Main::get_delay_js_base_preset_exclusions() (ARCH-005).
privatestatic get_delay_js_protected_exclusions()
private static function get_delay_js_protected_exclusions(array $file_opt): arrayManual + safe exclusions a per-page preset opt-out must never strip (issue #1308). Parameter Type Default Description $file_optarray— file_optimisation settings slice.
Return: string[] — Relocated from Main::get_delay_js_protected_exclusions() (ARCH-005).
public get_delay_js_preset_exclusions()
public function get_delay_js_preset_exclusions(): arrayGet curated delay JS preset exclusions (jquery, recaptcha, stripe, analytics, etc.).
Return: string[] — Relocated from Main::get_delay_js_preset_exclusions() (ARCH-005).
public is_delay_js_safe_context()
public function is_delay_js_safe_context(): boolWhether Delay-JS must be skipped for the current request (fail-open safe context).
Return: bool — True when Delay-JS must be skipped. Relocated from Main::is_delay_js_safe_context() (ARCH-005).
public add_fetchpriority_to_deferred()
public function add_fetchpriority_to_deferred($tag, $handle): stringAdds fetchpriority to rendered script tags for deferred handles. Parameter Type Default Description $tagstring— The script tag HTML. $handlestring— The script\’s registered handle.
Return: string — Modified script tag with fetchpriority. Relocated from Main::add_fetchpriority_to_deferred() (ARCH-005).
Hooks
Hooks referenced in includes/Assets/class-script-strategy.php: Hook Type Line Notes wppo_deferred_fetchpriorityfilter 537 @param ×2 wppo_deferred_in_footerfilter 583 @param ×2 wppo_exclude_delay_jsfilter 1315 — wppo_delay_js_preset_level_settingsfilter 2175 — wppo_delay_js_preset_level_exclusionsfilter 2287 — wppo_delay_js_third_party_denylistfilter 2654 — wppo_delay_js_third_party_allowlistfilter 2752 — wppo_delay_js_third_party_auto_categoriesfilter 3042 — wppo_delay_js_third_party_auto_patternsfilter 3261 — wppo_delay_js_exclusionsfilter 3727 —