Skip to content

Exclude WordPress core hooks/i18n from JS defer (inline translations call wp.i18n synchronously) - #1039

Open
Contributolo wants to merge 1 commit into
litespeedtech:devfrom
Contributolo:defer-excludes-wp-core-i18n
Open

Exclude WordPress core hooks/i18n from JS defer (inline translations call wp.i18n synchronously)#1039
Contributolo wants to merge 1 commit into
litespeedtech:devfrom
Contributolo:defer-excludes-wp-core-i18n

Conversation

@Contributolo

Copy link
Copy Markdown
Contributor

What

Adds wp-includes/js/dist/hooks and wp-includes/js/dist/i18n to the predefined JS Deferred / Delayed Excludes, and to the predefined JS Excludes so the two files are not swallowed into a combined file where the defer exclude could no longer match.

Why

On every localized site WordPress core prints inline scripts that call wp.i18n.setLocaleData() synchronously: wp-i18n-js-after plus one <handle>-js-translations block for each script that ships translations (Contact Form 7, WooCommerce, Elementor, block scripts, ...).

With Load JS Deferred = Deferred the external i18n.min.js / hooks.min.js get defer, while those inline blocks still run immediately during parsing (inline JS is not deferred in Deferred mode). The result on every page load is

Uncaught ReferenceError: wp is not defined
    source: wp-i18n-js-after, contact-form-7-js-translations, wp-a11y-js-translations, ...

This reproduces deterministically across many sites on LSCWP 7.9 with Deferred enabled; adding the two files to the site-level excludes removes the errors. hooks is a dependency of i18n. Both files are tiny (about 2 KB and 5 KB minified), so keeping them synchronous has no measurable cost, unlike excluding jQuery, which should stay a per-site decision.

Notes

  • Partial strings without the .min.js suffix also cover the SCRIPT_DEBUG variants (hooks.js, i18n.js).
  • a11y needs no entry: its inline block only calls wp.i18n.
  • Same pattern as the existing Turnstile entries, which are also present in both lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant