-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger page load listeners when no longer loading #23313
Merged
magento-engcom-team
merged 5 commits into
magento:2.4-develop
from
johnhughes1984:22909-domready-content-rendering-delay
Jan 24, 2020
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6d69673
Trigger page load listeners when no longer loading
johnhughes1984 cfde871
Merge branch '2.3-develop' into 22909-domready-content-rendering-delay
johnhughes1984 75f6a45
Skip test to due unrelated failure from incomplete action group
johnhughes1984 c44f0dc
Merge branch '2.4-develop' into 22909-domready-content-rendering-delay
slavvka 85ccb52
Merge branch '2.4-develop' into 22909-domready-content-rendering-delay
slavvka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue:
This condition automatically accepts any states which may be introduced in browsers in future.
For example: some browser adds state "initializing" and it breaks Magento2 UI, because it passes this check.
I would change it to following:
However it was previously done and caused issues for IE users: requirejs/domReady#1
If Magento2 doesn't support all IE versions then Ok, just add "interactive" as in code above - this is more stable version of logical statement.
BTW Google Chrome also fires "DOMContentLoaded" - it should work fine even without this change.
However, it might be that domReady.js is loaded and executed after DOMContentLoaded fired. It may happen if all static content is cached.
In this case we're waiting for readyState "complete" which makes a problem.
If you saw real improvement then probably this is the real case how it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just realized how it works: domReady.js is loaded via RequireJS, this is why it is subscribing to DOMContentLoaded after it fired.
It could be improved if domReady.js added to section statically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me and @ihor-sviziev tested both versions on our project.
Best performance shown when domReady.js is included into section. However you need to modify it's code a bit - add package name to AMD definition:
Benchmark results on real project with slow 3g mode enabled in Google Chrome dev console:
<head>
- first load: 9 sec, second load: 5 sec <== best resultTiming was measured by adding following code to
<head>
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment #25527 (comment). Specifically,
The
!== 'loading'
pattern is already how jQuery's$(document).ready(cb)
function works https://github.com/jquery/jquery/blob/05184cc448f4ed7715ddd6a5d724e167882415f1/src/core/ready.js#L66There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DrewML FYI in the latest version of jQuery it has changed
https://github.com/jquery/jquery/blob/3.5.1/src/core/ready.js#L67-L72
Maybe we need to change it also