Randy said:
What the Notes describes:
Browser encounters a script tag with a src attribute.
Browser retrieves that file.
File can't be retrieved.
Server sends 404 response.
Browser realizes the file isn't available.
Browser executes the script block.
The major difference, that you missed, is in the "404 page" versus "404
response".
And this is plain wrong from the first line to the last one.
Let's us go step by step:
1) The OP's problem: caused by the fact that it is impossible to
execute both external script and internal script:
<script src="file.js">
// statements
</script>
- all inner statements are ignored *if current UA supports src
attribute for <script> tag*.
If you have any problems with this common knowledge fact, please refer
to it as "Position 1" - so it wouldn't be mixed with other.
2) FAQ Notes statement:
<script src="file.js">
// statements
</script>
- statements will be executed if file.js is not available and this
fact is properly reported by server (over correct 404 page)
Plain wrong because if UA supports src attribute for <script> tag,
inner statements are ignored *on the page parsing stage* - so at the
moment script block is parsed by HTML parser, activated and making .js
file request - at this moment inner statements already skipped and do
not exist anymore. Parser do not hold them in some "buffer" in case if
the external resource is not available.
If you have any problems with this common knowledge fact, please refer
to it as "Position 2" - so it wouldn't be mixed with other.
3) Error page returned by server may affect on script behavior and even
cause errors. Plain wrong - as well as you seem to have a rather
specific idea about "proper 404 response". It is not a some kind of
bodyless error spirit sent by server - it is mainly the same
conventional HTML page with *headers set to right values*. The most
common on the Web Apache 404 page for example looks like:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /foobar.js was not found on this server.</p>
<hr>
<address>Apache/2.2.0 (Unix) Server at
www.apache.org Port 80</address>
</body></html>
That brings back the problem with your testcase - you're trying to say
that there is nothing augmented in it, but there definitely is.
Here is a sample to try - I used Apache.org error page with guaranteed
proper headers:
<html>
<head>
<title>Myth Buster v1.0</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script
type="text/javascript"
src="
http://www.apache.org/foobar.js">
alert('VK is wrong!');
</script>
</head>
<body>
</body>
</html>
If you manage to bring the message "VK is wrong!" up by changing
response headers and content, please report your succes as "Position 3"
- so it wouldn't be mixed with other.