First of all: I'm not talking about where each is executed, but what the differences in browser protocols is for fetching the script from the server (or so, I really have no clue).
I'm seeing a very strange behaviour that I can't explain and I can't find a reason for after a few days of searching on the internet.
The situation is as follows: I have some javscript that was originally stored in a .php file because there was some server side magic to be done upon fetching the script. It was called by the browser like this:
<script language="JavaScript" type="text/javascript" src="http://myserver.com/script.php"></script>
The javascript itself makes a few AJAX calls when loaded. In the (PHP) scripts activated by the AJAX calls I had a counter to keep track of traffic.
Now at some point the php magic done by script.php was removed, and I was able to simply turn the .php file into a .js like so:
<script language="JavaScript" type="text/javascript" src="http://myserver.com/script.js"></script>
It has exactly the same output, and makes exactly the same AJAX calls.
Here's the weird part: with the script.js my counter says there's 1/10th of the traffic there is with script.php. I can not figure out why it does this...
I checked the access.log of my server, and indeed, script.js gets far fewer requests than script.php did. When I revert to script.php the traffic instantly increases to 10/10th.
The main problem I have in debugging is that I can not reproduce the script not loading. I'm always in that 10% that does get the script to load/execute.
I tried to not let the script.js cache but that didn't help. I also tried watching if this behaviour was browser independant, but for me it works in FF, Chrome and IE. Furthermore, the useragent strings in the accesslogs aren't very helpfull on telling which browser it actually is.
If anyone could shine a light upon this, I'd be very thankfull.
[EDIT] Even if the js script comes from the cache, which is fine because it saves me on traffic bigtime, shouldn't it still be executed and make the AJAX calls? This doesn't happen either (Hence only 1/10th of traffic as shown by the counter)
[EDIT2] I just noticed that the script.php has Content-Type: application/javascript while the script.js has Content-Type: application/x-javascript Now I don't know if that could possibly cause this behaviour but I'll try to change it. Changing it, and changing script.js along with a newline so it needs a refresh didn't help...
<script>tag?languageattribute has long been deprecated, so don't use it