While going through old codebase I found a place where the previous software developer is using 

```js
$(function(a) {}(A || (A = {})));
```

which is executing even though the page is not ready yet. It started working after I removed the global variable being passed. Was the code done incorrectly the first time? 

final solution: 

```js
$(function() {});
```