<script> only loads half the time -- "Loading failed for the <script> with source", and only works when Firefox sends a range in the request - javascript

First off, apologies as I'm not experienced with StackOverflow. I also am clueless as to what the problem is.
I'm running a Flask server, and all other scripts have worked fine up to this point. However, when I attempt to load pdf.js in the same way, it only loads some of the time. Other times, it give this error in the Firefox console:
Loading failed for the <script> with source
However, I noticed that when it does work, it always sends a Range in the header.
I've tried loading it from another source, which worked fine. I've tried several different type in the <script> tag, from text/javascript to application/javascript to just blank. I've also tried changing how it's loaded in the JINJA2 template.
<script type="text/javascript" src="/static/pdfjs-dist/build/pdf.js">
</script>
Any ideas on what this is? Thank you!
EDIT:
Working Network Tab
Working Request
Non-Working Request
Non-Working Network Tab

Related

Soundcloud javascript SDK is giving 404 - not found

I just noticed that my web app that has a <script> tag:
<script src="https://connect.soundcloud.com/sdk/sdk-3.1.2.js"></script>
is no longer loading the javascript file. The network panel is showing "404 Not Found"
I also just entered the url https://connect.soundcloud.com/sdk/sdk-3.1.2.js in my browser, but I'm seeing a blank page.
Is something wrong with what I'm doing? Maybe the URL is not up to date? I'm following the "basic use" instructions at https://developers.soundcloud.com/docs/api/sdks#javascript
Here's a jsfiddle that only has the script loading tag. In the javascript console you'll see that it fails to load:
http://jsfiddle.net/dn0m23rs/1/
It's working now, it seemed to just have been a temporary outage. Sadly, nothing was indicated on the soundcloud status blog.

Why does Firefox DevTools' Debugger show 'loadSourceError'?

Consider this simple HTML file:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
alert('1');
</script>
</body>
</html>
When I enable Firefox JavaScript Debugger (via Ctrl+Shift+S), the panel shows me the following error message instead of the source code:
Error loading from source:
loadSourceError
What am I doing wrong?
My bet is that it comes from some server setting, since it works fine from another server (as well as locally), but I cannot identify any noticeable difference between both configurations (apache.conf are identical, /etc/apache2/sites-enabled/ configuration is similar, enabled modules are the same. I had the hope that installing the javascript-common debian package would help, but it does not…).
JavaScript itself is served correctly, though (even the embedded JS), and there is no loading problem for JS files.
Got it!
It seems that the debugger has issues with internationalized domain names (IDN).

Javascript files intermittently rendering as blank even when loaded from cache

I have a web application that loads a handful of javascript (10-15) files per page. The problem I'm having is some of these files get "loaded" as blank files according to Internet Explorer 10 Developer Tools, but the problem is not consistently reproducible. If you refresh the page a couple times, the .js file does load properly. This issue happens if the file is loaded from cache (response 304) or if it's fresh from the server (response 200). We use CTRL+F5 to force a 200 response. Obviously a "blank" javascript file is throwing all types of errors because the code is simply not there to execute.
Screen shot #1: The javascript file in question is search.js. But as you can see in developer tools under the script tab the file is "blank".
Screen shot #2: If we look under the network tab you can see the file was loaded OK
Now here is where it gets interesting, if you click on "Go to detailed view" button the Response body for this file is the correct Javascript code. The Request and Response headers look correct as well.
Has anyone ever seen this before? We can't seem to reproduce this problem in Chrome or Firefox but that doesn't mean it's not happening there.
<script type='text/javascript' src='wherever.js'></script> could be what you need. Most of those are showing up as application/javascript.

Mystery of the missing bootstrap

On my page I have boostrapped a javascript file to the head section. The URL is correct. The Javascript file exists on my server at that correct URL. I checked with fiddler2 and it shows that a server request is never sent for the file. The file has a simple test script
$(document).ready(function() {
alert("blah blah");
});
Now it was working just fine. It fired the alert every time I refreshed the page while I was working on that particular page for like 30 minutes. I got up, went to grab a soda and some left over pizza. Papa Johns of course. But when I came back and refreshed the page.. The javascript file no longer showed up bootstrapped to the head section. The alert no longer fires either.
<script type="text/javascript" src="js/events.js"></script>
Hmm so I cleared cache. Refreshed, but nothing.
Tried Firefox, Opera, IE, Safari and Chrome. Nothing.
Checked server. Still there and nothing. Chmod 777 to the file and
its directory. Nothing.
Checked console for errors. No errors and still, nothing.
Saved file and opened in notepad++, checked show all characters
(to find hidden treacherous keys), nothing unusual. Just Carriage
return and tab. But still of course nothing.
Mind blown. Help?
I rebooted my server and mysteriously it started working again. I'm sure there is perfectly logical explanation for this but it's something beyond the scope of my knowledge. If someone has an explanation, I would really like to hear it. If you want I can pull out server logs if you need them.
But suffice it to say its working again.

Resource interpreted as Script but transferred with MIME type text/plain - for local file

I'm getting a "Resource interpreted as Script but transferred with MIME type text/plain" warning in Google Chrome when including a local script file.
I know the problem appears when loading a file from a server or through ajax which most often depends on wrong headers being set.
The weird thing is that I get this warning even though it is run from a local folder: file:///C:/test/foo.html
This happens only in Chrome with the most basic html there is:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="bar.js"></script>
</head>
<body>
</body>
</html>
bar.js is also as simple as it can get:
function hello() {}
I've tried adding a meta tag:
<meta http-equiv="content-script-type" content="text/javascript">
and tested with other doctypes but nothing seems to help.
This obviously isn't a real issue since the scripts still work fine, but I'm working on a large project and currently have around 150 scripts included. It therefore makes it difficult to see when an actual warning occurs in between them.
Everything works fine when I run the file on a server, locally or remote.
Any ideas on why chrome is annoying me with this?
I figured it out!
The Visual Studio installer must have added an errant line to the registry.
open up regedit and take a look at this registry key:
See that key? The Content Type key? change its value from text/plain to text/javascript.
Finally chrome can breathe easy again.
I should note that neither Content Type nor PercievedType are there by default on Windows 7, so you could probably safely delete them both, but the minimum you need to do is that edit.
Anyway I hope this fixes it for you too!
I tried fixing this problem using this method but it didn't work for me.
My problem was that IIS manager didn't have MIME types in HTTP Features.
I was able to turn it on by enabling Static Context via...
--> Control Panel
--> Programs
--> Turn Windows features on or off
--> Internet Information Services
--> World Wide Web Services
--> Common HTTP features
--> [X] Static Content.
After this, MIME types appeared and everything started working again.
The accepted answer is a great one! However, just to post an answer for those who encounter problem like me, who use a department/college computer sometimes, where I do not have the permission to change any key value in regedit.
Change
<script type="text/javascript" src="main.js"></script>
to
<script src="main.js"></script>
Although the error message still exist, the page loaded correctly.

Categories