tags:

views:

83

answers:

3

I have some legacy html code that uses #include file = "filename.js" derective to load .js files to html page. The problem is that the files are not loaded. When I try script src attribute it works fine, that means that the path is right. I use vs2003, windows XP Pro, IIS 5.1 . Do you have any idea why the .js files are not loaded when I use #include file derective.

Thanks a lot, Daniel

+2  A: 

Include file requires your server to be configured properly for the allowance of Server-Side-Includes. Take a look at Microsoft's IIS 5.1 information on setting up ASP and SSI on your XP box: Microsoft IIS SSI Setup. Navigate to the section titled: ASP and SSI settings on IIS

drlouie - louierd
+4  A: 

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>
Guffa
A: 

Thanks to you all for the useful information. I have investigated more the server-side-includes issue. I found out that I need to add .htm file mapping to ssinc.dll in the IIS configuration and it solved the problem.

Daniel Kabzon