Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include files

Status
Not open for further replies.

stvchez123

Programmer
Apr 18, 2002
59
US
I am trying to do an include from an external file to clean up my page. Here is the include:

<!-- #INCLUDE file = &quot;js/headerJS.html&quot; -->

This is a javascript header portion and works perfectly when solely in the page (the include file was placed within the header tags). Is there anything I'm missing or are you not allowed to use javascript in includes for some reason? thanks
 
To include JS, it would be something like:
<script src=&quot;js/headerJS.js&quot;>
</script>

And not an HTML file. Unless of cours are you naming the page with a SHTML extension so it will be parsed on the server or do you have the server set up to parse HTML files?

__________________________
Corey

 
Like Corey says, many web servers expect pages to end with a .shtml extension if they are to be parsed for server side includes. Assuming you've done that, I think it might also object to the spaces before the # and around the =. Try
[tt]
<!--#INCLUDE file=&quot;js/headerJS.html&quot; -->
[/tt]
You can check whether it's working - view the page as served up by your web site & do a &quot;View Source&quot; - you should see the contents of headerJS.html instead of the INCLUDE statement.

For javascript, you're best off putting it in a seperate file and referencing it with a src= attribute as Corey did. That way the script can get cached by the browser instead of being downloaded each time. It doesn't confuse HTML validators so much either. You can still &quot;include&quot; the empty script tags as it makes it easy to change/add stuff en masse later on. In fact, I'd advise you to make all your pages look like this:
[tt]
<html>
<head>
<title>Page Title Here</title>
<!--#include file=&quot;/inc/head.txt&quot; -->
</head>
<body>
<!--#include file=&quot;/inc/top.txt&quot; -->
This is the main unique content of the page
<!--#include file=&quot;/inc/bottom.txt&quot; -->
</body>
</html>
[/tt]
I use the three included file to put in whatever standard content is required in those places to provide menu bars, standard logos, meta tags, javascripts whatever. The basic document remains a syntactically valid HTML document, but with as little duplicated content as possible. You can change the whole look of the site with a little editing to one or more of the .txt files.

Finally, there's a load of information abou SSIs in faq253-3309 and faq253-2000 .


-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top