Forum Moderators: coopster & phranque

Message Too Old, No Replies

SSI in <head> tags?

Is it possible to use SSI in a head tag?

         

madmatt69

8:46 am on Sep 28, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello everyone!

I've got this problem - I use several external .js files throughout my website, and was thinking it would be efficient to just put those links in an SSI. So here's the SSI file (ssi.htm) ----

<script language="JavaScript" src="scripts/mouseover.js" type="text/javascript"></script>
<script language="JavaScript" src="../../scripts/mm.js" type="text/javascript"></script>

----

Sorry if it looks a little messy. Basically it's just the html to link the external .js files.

Now in the <head> tag of my site, I put the following code ----

<!--#include virtual="header.htm" -->

----

But it doesn't work! Can anybosy shed some light on this? Perhaps I've just got a syntax error or something?

Thanks in advance,

Matt..

joshie76

10:26 am on Sep 28, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi MadMatt and welcome to WebMasterWorld.

You say the file is called ssi.htm but it looks like you are trying to load an include called header.htm

madmatt69

2:17 pm on Oct 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the welcome, and the advice, but I wish it were that simple. That was just a type-o in my email. Sorry about that! When I wrote ssi.htm I meant header.htm. But do you think it's possible to have SSI's in the <head> tag of a document? I do, but I still can't get it to work. I'm pretty sure my server supports them....anybody else have an idea?

Thanks again,
Matt..

joshie76

2:25 pm on Oct 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can have an SSI absolutely anywhere in your document. SSI templates don't have to be well formed or follow any rules - it just replaces the include tag with the source of the named file.

Now you mention I have had similar non-sensical problems.. Try using the file attribute instead of virtual.. i.e. <!--#include file="header.htm" --> -- This bodge has worked for me in the past when the SSI wasn't behaving.

Josh

madmatt69

9:23 am on Oct 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah! That seemed to work. Thanks for the help!

On a side note though...
If you include meta tags in a SSI, would those still be crawlable by a search engine spider? I somehow doubt it, but it'd be cool if they could. Just a thought -

Thanks again,
Matt..

joshie76

9:27 am on Oct 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yup, the page is served up with the include expanded.

Example

INCLUDE FILE (inc.htm): hello this is the include

FILE REQUESTED: if the include works then the include will appear here <!--#include file="inc.htm"-->.

Then anything that requests your page will receive the almagamated file that would look just like this:

if the include works then the include will appear here hello this is the include.

Hope that helps clear it up. As a side note - beware of using the same metas on every page (i guess that is what you are possibly thinking of doing) as this may not be the best way to SEO your site.

Brett_Tabke

8:30 am on Oct 4, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What you see in the browser when you view the source, is just what the search engines see for source.

netcommr

11:35 pm on Oct 9, 2001 (gmt 0)

10+ Year Member




I think the reason you were having trouble getting 'header.htm' to be included is it may not be able to be virtually included.

To have your documents parsed by the server you need to tell the server what file extension to parse. Most servers will not parse htm or html documents because this will slow down the machine. So, it has become a standard to use something like 'shtml' for server parsed documents, yours may be something else. To include a document with the virtual attribute, such as <!--#include vitual="header.htm"-->, header.htm must be a server parsable file. So if you change the name of the file to header.shtml, or what ever file extension you are using, this will fix your problem. Such as <!--#include virtual="header.shtml"-->

Basically, the file you are including with the virtual attribute MUST be an SSI document itself.

Includes with the 'file' attribute do not have this limitation.

I hope that was helpful as I run into this many times and find it a common challenge with my clients also.

madmatt69

9:16 am on Oct 10, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, someone was mentioning that to me the other day. I was thinking I might have to modify the .htaccess file or something, but the SSI's are working fine now.

Thanks to everyone for the comments!

joshie76

9:23 am on Oct 10, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nice one Netcommr.. I always wondered why virtuals never worked too.

Cheers ;)