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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#includes - can I use them like this?? 1

Status
Not open for further replies.

lovejaeeun

Technical User
Jan 13, 2004
60
US
I have a template for a website that uses tables for layout. All the pages are identicle except for the text that goes in the 'main' cell of each page.

After I wrote out my template in HTLM, i just cut them up and saved them as 1.inc, 2.inc, 3.inc and used #includes (as shown in my code below).

I did this because if I want to make a change to the website, like add another column, this way I could just edit 2.inc, for example, instead of having to make the change to every page in the site.

I want to know if this way is OK but even better I would like to know perhaps what the standard practice is for such a thing. (meaning what do people do to make their web sites easily changeable)

Any input would be appreciated.

Thanks,



<!-- MY CODE -->

<html>
<head>
<title>BLAH BLAH</title>
<!--#include virtual=&quot;/metta.inc&quot;-->
<!--#include virtual=&quot;/styles.asp&quot;-->
</head>

<!--#include virtual=&quot;/1.inc&quot;-->
<!--#include virtual=&quot;/navigationBar.asp&quot;-->
<!--#include virtual=&quot;/2.inc&quot;-->

<div class=&quot;main&quot;>
Write whatever here
</div>
<!--#include virtual=&quot;/3.inc&quot;-->
 
That is certainly the way I tend to code my sites. It works well for my needs. I have a few page specific ASP variables declared at the top that are then used in header.asp and footer.asp.

Code:
<!--#include file=&quot;include/globalfunctions.asp&quot;-->

<%
strTitle = &quot;Page title here&quot;
strFilename = &quot;home.asp&quot;
%>

<!--#include file=&quot;include/header.asp&quot;-->

'individual page content here

<!--#include file=&quot;include/footer.asp&quot;-->



Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
I also code in this way - becasue of the flexibility it allows.

Bear in mind a couple of things.

Includes are always parsed, watch out for really big includes - server.execute is another option (watch out for maintaining state though)

I always use .asp file extensions rather than .inc as asp pages are always executed by the server, inc files can be downloaded without execution.

Simon
 
simonchristies (or anyone that wants to reply),

The contents of the '.inc' files are just static HTML so i purposely did not use the .asp file extenstion.

I did this because I thought it would save server resources this way because it would be a waste for IIS to go through the include when there is nothing for it to do.

Am I right for doing this? Or should I just use the .asp extension anyways?

Also, what do you mean when you say includes are always parsed? (sorry I am kinda new to all this). Are you basically telling me the same thing i was worried about? - that IIS has to go through the entire file? - and that i should keep the includes as short as possible?

Thanks!

 
If you are just using html then it will make no difference, however if you were using asp code in an include file then that file can be downloaded be fore being run - if you were to have database information / security information there then it could cause a security breach, adding an asp file ext. just tells the server to run the code when the page is called.

As for keeping pages as short as possible, the best you can ever do is optimise you code, and draw that fine line between functionality and useability, it's no good having an all singing/all dancing web page that is 1meg and takes 35 secs to download.

hth

simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top