Skip to content

Commit

Permalink
Improve domReady performance for faster load times
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Krzeszowiak committed Feb 7, 2020
1 parent 5c160b6 commit 40c36ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@
"description": "Fixes collapsible issue with scrollin to the content even if it is visible",
"filename": "essential/m233-collapsible-scrolling-fix.patch",
"version-constraint": "2.3.3"
},
{
"description": "Improve domReady performance for faster load times",
"filename": "essential/m23-improve-domready-performance.patch",
"version-constraint": ">=2.3.2,<2.3.5"
}
],
"magento/module-search": [
Expand Down
32 changes: 32 additions & 0 deletions essential/m23-improve-domready-performance.patch
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
+});

0 comments on commit 40c36ae

Please sign in to comment.