Chrome just doesn't finish loading JS files

前端 未结 6 1352
名媛妹妹
名媛妹妹 2021-02-05 05:51

I am writing an app that includes about 12 short JS files in the section (I know, I should merge them and move them just before the end of

相关标签:
6条回答
  • 2021-02-05 06:28

    There are several good answers, but if you want a foolproof method of doing this, you can use PHP to send all the scripts at once. If the problem is truly too many connections to the server, you could add some html code like this:

    <script type="text/javascript" src="scripts/scripts.php />
    

    And then in scripts.php you use the include() function to include all of the JavaScript files like so:

    <?php
    header(''); // control all your headers
    include('jquery-1.9.1.min.js');
    // rest of scripts
    ?>
    

    If nothing else works and the problem is excessive connections, this should work.

    0 讨论(0)
  • 2021-02-05 06:35

    One possibility is that you have Keep-Alive enabled and it is not working properly. I've seen this before. The browser establishes it's maximum number of connections to your server (typically 6) to download the first few files (CSS, JS etc.) then those connections are not released until they time out. My symptoms were not quite the same as yours - the timeout was 20 seconds and everything would load in batches of 6 after that - but this could still be the cause.

    In your Apache configuration (httpd.conf on most systems), look for the KeepAlive line (or add it if it's missing) and set it to Off.

    0 讨论(0)
  • 2021-02-05 06:35

    More than an answer, here's how I would troubleshoot the problem.

    One of the things I'd try is commenting out tags one at a time and reload, to see where the threshold is. Also, because this is probably a server configuration problem, I'd restart it after each try, to have a clean slate, so to speak, i.e., no state preserved between tries.

    I'd try to get more hints by trying to make the requests for the various Javascripts from a script in your favourite language. Ideally, I'd try GETting the scripts one by one (say with curl) waiting a few milliseconds between requests. I imagine I'd hit a threshold here as well. Like, getting one script per second works, but when requests get too close, the server gets stuck.

    If still no clue, I'd use tcpdump to watch the traffic between the browser and the server. Okay, this may be a little too low level!

    But perhaps I'd use netstat to see how many connections the browser opens in parallel to the server to fetch the resources, and see if we hit a concurrency limit.

    I'm sorry this is a solution but I hope you get some ideas, and I'd be very curious to know what your problem is, in the end!

    0 讨论(0)
  • 2021-02-05 06:48

    Try to emulate problem in https://www.stevesouders.com/cuzillion/ It should say you side of problem - chrome or server

    0 讨论(0)
  • 2021-02-05 06:51

    Check the Content-Length header. Server may pass incorrect value - greather than actual content length.

    0 讨论(0)
  • 2021-02-05 06:54

    We got exactly the same message "Caution: request is not finished yet" after a request in the browser.

    The request itself was in the order of 15 MB of JSON, which was fed into an Angular 1 application. This request took about 2 seconds. Right after the request was finished, the Angular digest cycle blocked the browser for more than 12 seconds (this is visible by profiling during the request). During that time Chrome showed this "Caution: request is not finished yet" message in request whilst it actually was already finished.

    0 讨论(0)
提交回复
热议问题