views:

312

answers:

6

Say I have several JavaScript includes in a page:

<script type="text/javascript" src="/js/script0.js"></script>
<script type="text/javascript" src="/js/script1.js"></script>
<script type="text/javascript" src="/js/script2.js"></script>
<script type="text/javascript" src="/js/script3.js"></script>
<script type="text/javascript" src="/js/script4.js"></script>

Is there a way i can tell if any of those weren't found (404) without having to manually check each one? I guess i'm looking for an online tool or something similar. Any ideas?

+8  A: 

If you get the Firebug firefox plugin and enable the consoles it should tell you when there are errors retrieving resources in the console.

Alex Argo
I would get a syntax error:Error: syntax errorSource File: http://localhost/js/bad/filename/file.jsLine: 1Source Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" Instead of a 404, alerting me of the problem. This also appears in the firefox console
SeanDowney
Open the "Net" tab in Firebug and enable it. Than refresh.
Andy Li
+2  A: 

I don't use other browsers enough to know where to find a similar feature in them, but Safari has an Activity window that displays all of the included files for a given web page and which ones were unable to be retrieved.

John Calsbeek
+1  A: 

Log your 404's.

Joel Coehoorn
this would work, except the site i'm working on display's a "Page not found" instead of a 404. So I would get 200's for things that didn't exist!
SeanDowney
You could send a 404 header, and still show the Page not found message.
Adam
+2  A: 

If you want to monitor on the fly without actually checking if it exists, then I suggest placing dynamic variables inside the files. Then just do something like this:

var script0Exists = true; // inside script0.js
var script1Exists = true; // inside script1.js

Then in your other files, just use:

if ( script0Exists ) {
    // not a 404 - it exists
}
hal10001
A: 

If you don't want to check it manually on the client you will need to do this server-side. You need to make sure whichever webserver you are using is configured to log 404s and then check that log to see which HTTP requests have failed.

A: 

If your webhost always returns the HTTP result "200 OK", whether the file exists or not (the latter should give a "404 Not Found"), the browser has no way of telling if it received a script or not.

You might try retrieving the files via XMLHttpRequest, examine the data, and if they look like JS, either eval() them, or create a script tag pointing to the exact same URL you downloaded (if the script is cacheable, it won't be transferred again, as the browser already has it).

Piskvor