The #include directive is a server side function, not something that the browser does. Therefore you can't verify that the file name is correct by using it in a script tag, as that is loaded by the browser.
If you try to include a file that doesn't exist, the server will return an HTTP 404 error message, it will not silently ignore the #include.
The page has to be processed by the server for the #include tag to work, i.e. it has to have a file type that the script engine handles like .asp
or .shtml
. If you put an #include tag in an .htm
or .html
file, it won't be processed.
A proper #include tag looks like this:
<!--#include file="filename.js"-->
It can also use virtual addressing, i.e. the path originates from the root instead of the folder where the page is:
<!--#include virtual="filename.js"-->
Note that the file that you are including has to have a script tag in it to be treated as script by the browser, or you have to put a script tag around the include:
<script type="text/javascript"><!--#include file="filename.js"--></script>