$(document).ready and $(window).on('load') in jQuery 3.4.1

$(document).ready and $(window).on('load') in jQuery 3.4.1

Hi,

I'm currently in the process of trying to upgrade a site from jQuery 2.2.4 to 3.4.1 but I am having issues with the order in which $(document).ready and $(window).on('load') are firing. My understanding is that $(document).ready should always fire first but this doesn't seem to be the case. 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").

Has this behaviour changed in 3.4.1?


  1. <html>
       <head>
           <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
           <!--<script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script>-->
       </head>
       <body>
          <div>Isn't window.onload meant to load last?</div>
          <script>
      $(document).ready(function () {
       console.log("document loaded");
      });
  2.   $(window).on('load', function () {
       console.log("window loaded");
      });
          </script>
       </body>
    </html>


Thanks in advance!