Skip to content

Page Optimize: delay scripts that already have defer in Delayed mode - #1070

Merged
hi-hai merged 1 commit into
litespeedtech:devfrom
timotei-litespeed:fix-delay-native-defer
Oct 16, 2026
Merged

hi-hai merged 1 commit into
litespeedtech:devfrom
timotei-litespeed:fix-delay-native-defer

Conversation

@timotei-litespeed

Copy link
Copy Markdown
Contributor

With Load JS Deferred set to Delayed and JS Combine off, _js_defer() left any script that already had a defer attribute untouched. WordPress prints defer for scripts registered with the defer strategy, which WooCommerce uses for woocommerce.js, add-to-cart, cart-fragments, js-cookie and blockui. Those files then ran natively at DOMContentLoaded while their inline data (woocommerce-js-extra, wc-add-to-cart-js-extra) waited for user interaction, so woocommerce.js failed with "woocommerce_params is not defined".

In Delayed mode such scripts now drop defer and join the delay queue, which runs them in document order after their inline data. Deferred mode still leaves an existing defer as is, and data-no-defer and the defer exclude list keep working.

With Load JS Deferred set to Delayed and JS Combine off, _js_defer() left any
script that already had a defer attribute untouched. WordPress prints defer
for scripts registered with the defer strategy, which WooCommerce uses for
woocommerce.js, add-to-cart, cart-fragments, js-cookie and blockui. Those
files then ran natively at DOMContentLoaded while their inline data
(woocommerce-js-extra, wc-add-to-cart-js-extra) waited for user interaction,
so woocommerce.js failed with "woocommerce_params is not defined".

In Delayed mode such scripts now drop defer and join the delay queue, which
runs them in document order after their inline data. Deferred mode still
leaves an existing defer as is, and data-no-defer and the defer exclude list
keep working.
@hi-hai
hi-hai merged commit 18b5043 into litespeedtech:dev Oct 16, 2026
1 check passed
@timotei-litespeed
timotei-litespeed deleted the fix-delay-native-defer branch October 16, 2026 15:05
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.

2 participants