Skip to content

Skip JS preload hints when load-on-intent mode is active#622

Merged
fballiano merged 2 commits intomainfrom
fix/skip-preload-hints-load-on-intent
Mar 4, 2026
Merged

Skip JS preload hints when load-on-intent mode is active#622
fballiano merged 2 commits intomainfrom
fix/skip-preload-hints-load-on-intent

Conversation

@fballiano
Copy link
Contributor

Summary

  • The minification helper (sendEarlyHint) sends Link: rel=preload; as=script HTTP headers for every JS file during head rendering
  • These preload headers instruct the browser to download all scripts immediately, completely bypassing the type="text/plain" load-on-intent deferral mechanism
  • This fix skips sending preload hints for JS files when load-on-intent defer mode is active, preserving the intended behavior of deferring both download and execution until user interaction

Test plan

  • Enable JS minification and load-on-intent defer mode
  • Load a frontend page and check browser Network tab
  • Verify JS files are NOT downloaded until user interaction (click, scroll, etc.)
  • Verify CSS preload hints still work normally
  • Verify JS preload hints still work when defer mode is disabled or set to defer-only

The minification helper sends Link: rel=preload HTTP headers for every
JS file, which instructs the browser to download scripts immediately.
This defeats the purpose of the load-on-intent defer mode, which is
designed to delay both downloading and execution until user interaction.
@fballiano fballiano changed the title Skip JS preload hints when load-on-intent mode is active Skip JS preload hints when load-on-intent mode is active Mar 4, 2026
Copy link
Contributor Author

@fballiano fballiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style nit: the two nested if statements could be a single condition with &&:

if ($as === 'script'
    && (int) Mage::getStoreConfig('dev/js/defer_mode') === Mage_Core_Model_Source_Js_Defer::MODE_LOAD_ON_INTENT
) {
    return;
}

PHP short-circuits &&, so getStoreConfig is still only called for script assets — same behavior, just cleaner.

@fballiano fballiano merged commit 7c813ce into main Mar 4, 2026
22 of 23 checks passed
@fballiano fballiano deleted the fix/skip-preload-hints-load-on-intent branch March 4, 2026 16:08
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