# decorateCookedElement for each page change?

**URL:** <https://meta.discourse.org/t/decoratecookedelement-for-each-page-change/214218>\
**Category:** Development\
**Created:** [January 8, 2022, 4:54am UTC](https://meta.discourse.org/t/decoratecookedelement-for-each-page-change/214218 "2022-01-08T04:54:17Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jimkleiber](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jimkleiber/32/121814_2.png) [@jimkleiber](https://meta.discourse.org/u/jimkleiber)\
**Post date:** [January 11, 2022, 8:54pm UTC](https://meta.discourse.org/t/decoratecookedelement-for-each-page-change/214218/4 "2022-01-11T20:54:12Z")

</div>

A follow up and maybe a dumb question: I’m trying to load multiple scripts now, as the Mediaelement allows plugin scripts. I want to make sure all the scripts load before returning the promise.

I’ve tried to do it through looping through the constants of the script sources and then creating an array of promises, then using Promise.all() for the initializing of the players, and yet when I do, I’m getting an error saying that `mejs` is not found, which I believe is the namespace or something for calling different functions within the mediaelement-and-player.

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/6/f671c5ea5f12f4a5fc848e0003d4b333806a9970.png)

```javascript
      let scripts_loaded = [];
      
      MEDIA_ELEMENT_SCRIPTS.forEach(function (src, index){
          scripts_loaded[index] = loadScript(src);
      });
      
      Promise.all(scripts_loaded).then(() => {
            audioplayers.forEach(function (el) {
              new MediaElementPlayer(el, MEDIA_ELEMENT_CONFIG);
            });
      });

```

However, if I chain them manually, it seems to work, as such:

```javascript
      loadScript(MEDIA_ELEMENT_SRC).then(() => {
          loadScript(MEDIA_ELEMENT_SPEED_SRC).then(() => {
            loadScript(MEDIA_ELEMENT_SKIP_BACK_SRC).then(() => {
                loadScript(MEDIA_ELEMENT_JUMP_FORWARD_SRC).then(() => {
                    audioplayers.forEach(function (el) {
                        new MediaElementPlayer(el, MEDIA_ELEMENT_CONFIG);
                    });
                });
            });
        });
      });

```

In this instance, I’m only using a handful of scripts, so I just manually typed them all in, I was just curious if I’m missing something obvious about the Promise.all() function, or if there is a Discourse function that allows me to load multiple scripts from an array.

---

_[View the full topic](https://meta.discourse.org/t/decoratecookedelement-for-each-page-change/214218)._
