2

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?

6 Answers 6

9

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

Sign up to request clarification or add additional context in comments.

2 Comments

I would get a syntax error: Error: syntax error Source File: localhost/js/bad/filename/file.js Line: 1 Source 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
Open the "Net" tab in Firebug and enable it. Than refresh.
2

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.

Comments

2

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
}

Comments

1

Log your 404's.

2 Comments

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!
You could send a 404 header, and still show the Page not found message.
0

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.

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.