Server Side Includes for page reuse

Posted by webstuffscan on November 23rd, 2006


Server Side IncludeConsider the following scenarios,
1. Multiple blogs with shared content. You have couple of blogs and you want some common piece of information on all blogs(possibly on side bar, header or footer).

2. Single blog with multiple templates. You have a Movable Type installation and you want some common information across index pages and archive pages.

The commonly followed practice is to include the page fragment in all pages. This becomes a nightmare after a while. Whenever there is a change in the common page fragment you have to change all related pages.

Blogging tools such as Movable Type provides some mechanism to include other files. For example, MTInclude directive can be used to reuse page fragments. The problem with this approach is that you have to rebuild all the pages and for a large installation can take a lot of time.

The perfect solution to this problem is to use server side includes. For this your Web server must be configured for server side include (Most hosting providers enable this by default). For example in my Movable Type templates I have the following line,

...
<div id="banner">
<!--#include virtual="/navbar.html" -->
</div>
... 

In the above case note the virtual attribute in the include directive. This means that navbar.html is searched from the root of your web server. Another alternative is to use file attribute.

More Resources
Using MTInclude and PHP Include
Apache Tutorial on Server Side Include

Related Stuff
Copyright is retained by webstuffscan

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word