Skip to content

Commit c37284f

Browse files
ENGCOM-7146: Move JS module initialization to separate tasks #27360
- Merge Pull Request #27360 from krzksz/magento2:mage-cpu-load - Merged commits: 1. 5c5d32f 2. 334a84e
2 parents ac3eb00 + 334a84e commit c37284f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/web/mage/apply/main.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,23 @@ define([
2222
*/
2323
function init(el, config, component) {
2424
require([component], function (fn) {
25+
var $el;
2526

2627
if (typeof fn === 'object') {
2728
fn = fn[component].bind(fn);
2829
}
2930

3031
if (_.isFunction(fn)) {
31-
fn(config, el);
32-
} else if ($(el)[component]) {
33-
$(el)[component](config);
32+
fn = fn.bind(null, config, el);
33+
} else {
34+
$el = $(el);
35+
36+
if ($el[component]) {
37+
fn = $el[component].bind($el, config);
38+
}
3439
}
40+
// Init module in separate task to prevent blocking main thread.
41+
setTimeout(fn);
3542
}, function (error) {
3643
if ('console' in window && typeof window.console.error === 'function') {
3744
console.error(error);

lib/web/mage/bootstrap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ define([
1616

1717
/**
1818
* Init all components defined via data-mage-init attribute.
19+
* Execute in a separate task to prevent main thread blocking.
1920
*/
20-
$(mage.apply);
21+
setTimeout(mage.apply);
2122
});

0 commit comments

Comments
 (0)