I
I
Igor2018-09-21 08:29:11
Drupal
Igor, 2018-09-21 08:29:11

Why does $(document).ready fire 6 times on Drupal8?

Curious moment. I replaced that $(document).ready fires several times, and when the blocks have not yet appeared, it also fires. This generates a lot of unnecessary operations and errors, because. many elements are still missing.
How can this be explained and how to fight?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
afi13, 2018-09-21
@pingvin156

https://www.drupal.org/docs/8/api/javascript-api/j...

L
Lander, 2018-09-21
@usdglander

1. $(document).ready fires only once after the DOM is formed, but there can be several handlers for this trigger. In your case, there are six.
2. If the blocks did not appear, but ready worked, then the blocks are added dynamically. Either through js or using AJAX. In this case, you need to build the correct order for loading js files and / or use callback functions to process the result of the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question