Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome just doesn't finish loading JS files

Tags:

I am writing an app that includes about 12 short JS files in the <head> section (I know, I should merge them and move them just before the end of <body>; would get to those when in production)

The trouble is that when I try to load the app in Chrome, Some files load immediately while some never finish loading at all! Chrome keeps trying to load the 12 JS files and never renders the page until I hit "Stop".

When I hit stop, the HTML is rendered and the JS files fail as in the image below:

JS Load errors

Note that different JS files fail on each attempt! It's not the same file that gets stuck every time!

Inspecting the headers of the failed files shows "Caution: request is not finished yet". The files are stuck in "Receiving" sometimes for many minutes!

enter image description here

Now here's the fun part, after hitting stop, if I focus on the omnibar and press enter, all the JS files load instantly and the application works fine!

On the server side, I am using Apache, PHP and MySQL. Have I misconfigured something in Apache?

STATUS after 2 gruelling days: zilch, nothing, nada, this is driving me nuts. I have tried running the code from different machines, have tried changing apache cache settings and changed myriad things in javascript but nothing has worked. The worst thing is that no one can pin point where the problem is!

like image 971
KJ Saxena Avatar asked Sep 15 '14 11:09

KJ Saxena


People also ask

Why is my JavaScript not working on Chrome?

Google ChromeIn the "Settings" section click on the "Show advanced settings..." Under the the "Privacy" click on the "Content settings...". When the dialog window opens, look for the "JavaScript" section and select "Allow all sites to run JavaScript (recommended)". Click on the "OK" button to close it.

What happens when browser is not able to load JavaScript?

Many Internet Web sites contain JavaScript, a scripting programming language that runs on the web browser to make specific features on the web page functional. If JavaScript has been disabled within your browser, the content or the functionality of the web page can be limited or unavailable.

Why js file is not working in HTML?

You should put all javascript code in a <script> tag for the browser to recognize and make it run and for the src attribute of the script tag to find your 'script. js' file, it just has to be in the same directory as the html file, you don't need to specify the entire file root.


2 Answers

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.

like image 64
Dave Morrissey Avatar answered Oct 29 '22 21:10

Dave Morrissey


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!

like image 34
nicolagi Avatar answered Oct 29 '22 19:10

nicolagi