-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve domReady performance for faster load times
Based on magento/magento2#23313
- Loading branch information
Mateusz Krzeszowiak
committed
Feb 7, 2020
1 parent
5c160b6
commit 40c36ae
Showing
2 changed files
with
37 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
diff --git a/lib/web/requirejs/domReady.js b/lib/web/requirejs/domReady.js | ||
index 31bd0d7..099c6f7 100644 | ||
--- a/lib/web/requirejs/domReady.js | ||
+++ b/lib/web/requirejs/domReady.js | ||
@@ -78,7 +78,7 @@ define(function () { | ||
} | ||
} | ||
|
||
- //Check if document already complete, and if so, just trigger page load | ||
+ //Check if document is no longer loading, and if so, just trigger page load | ||
//listeners. Latest webkit browsers also use "interactive", and | ||
//will fire the onDOMContentLoaded before "interactive" but not after | ||
//entering "interactive" or "complete". More details: | ||
@@ -89,8 +89,9 @@ define(function () { | ||
//so removing the || document.readyState === "interactive" test. | ||
//There is still a window.onload binding that should get fired if | ||
//DOMContentLoaded is missed. | ||
- if (document.readyState === "complete") { | ||
- pageLoaded(); | ||
+ if (document.readyState !== "loading") { | ||
+ // Handle it asynchronously to allow scripts the opportunity to delay ready | ||
+ setTimeout(pageLoaded); | ||
} | ||
} | ||
|
||
@@ -126,4 +127,4 @@ define(function () { | ||
/** END OF PUBLIC API **/ | ||
|
||
return domReady; | ||
-}); | ||
\ No newline at end of file | ||
+}); |