# JavaScript Execution Time

**URL:** https://meta.discourse.org/t/javascript-execution-time/299356
**Category:** Development
**Created:** [March 14, 2024, 3:53pm UTC](https://meta.discourse.org/t/javascript-execution-time/299356 "2024-03-14T15:53:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![abdul19](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abdul19/32/368523_2.png) [@abdul19](https://meta.discourse.org/u/abdul19)
#### Post date: [March 14, 2024, 3:53pm UTC](https://meta.discourse.org/t/javascript-execution-time/299356/1 "2024-03-14T15:53:21Z")

</div>

Sometimes the JavaScript file is executed before the DOM is completely rendered. The problem caused by this is while trying to access the DOm elements, it gives an error saying the element does not exists. For the moment, We have use the setTimeOut method to delay the execution for half a second which is not a good solution nor a good practice.  
So, the question is how to change the JavaScript file to execute only if the DOM is fully generated?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 14, 2024, 3:56pm UTC](https://meta.discourse.org/t/javascript-execution-time/299356/2 "2024-03-14T15:56:16Z")

</div>

That’s expected if you build your extensions using inadequate hooks, like `$( document ).ready` or anything like that.

Discourse is an EmberJS app, so any extensions should take that into consideration and hook into the app existing hooks. You can learn about that at [Developing Discourse Themes & Theme Components](https://meta.discourse.org/t/beginners-guide-to-developing-discourse-themes/93648)

---

<div class="post-metadata">

### Author: ![abdul19](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abdul19/32/368523_2.png) [@abdul19](https://meta.discourse.org/u/abdul19)
#### Post date: [March 14, 2024, 4:02pm UTC](https://meta.discourse.org/t/javascript-execution-time/299356/3 "2024-03-14T16:02:53Z")

</div>

@Falco Thank you very much for responding. I will have a look at it and let you know if it worked
