Why do we calculate the second half of frequencies in DFT? In the following example the console shows "window loaded" before "document loaded" when using jQuery 3.4.1 but when using jQuery 2.2.4 it always works as expected ("document loaded" appears before "window loaded"). You should refresh several times - and you will see that with $(document).ready() height of image doesn't matter - because it doesn't loaded, but $(window).load() case shows bigger value (because image is loaded). . $ (document).ready and $ (window).on ('load') in jQuery 3.4.1 Then keep all event listeners inside the ready handler and call any functions on demand. If possible I would rather not have to redesign the javascript code execution order or have to touch any other code apart from function a(). The code tries to load a website URL in an