Build Easy

Monday, August 21, 2006

title iconFirst of all, SSI: How easily you can maintain your website

One of the best things you can do with SSI(Server Side Include), is to slice a normal HTML page into several common parts such as header and footer, so that you can more easily update a website of hundreds of thousands of pages for just a slight alteration of a single file. And this is accomplished by the following directives:


<html>
<!--#include virtual="path/to/the/header.txt" -->
...primary content goes here...
<!--#include virtual="path/to/the/footer.txt" -->
</html>

(I used HTML entities to represent tags in this example. Chances are you will encounter some cases where the use of an HTML entity is necessary, such as when you are writing copyright notice. So why not have a look at the HTML entities page I have made? It's here!)


As you have guessed, codes between the HTML tags are those that we want to display in the client's browser, while header.txt and footer.txt contain the HTML snippets that are used throughout the whole website. Instead of putting them directly in all the HTML files, we have abstracted them into separate files and linked them from the files that need them. In this way, once we feel like deleting a link in the navigation bar, for example, we just remove the corresponding codes in the header.txt, and effects are immediately seen throughout the website. Maintenance made much easier, huh?

However, merely inserting a directive like <!--# include virtual="..." --> into a normal HTML file with an extension of .html or .htm doesn't give you the advantages described to you. You have to name it with .shtml, or it won't work. Remember, as long as there are SSI directives you want the web server to parse, you should name the file containing them with an extension of .shtml. And what if you write a directive like this:


<!--#include virtual="path/to/the/header.shtml" -->


In this case, the server first read the directive, locate the header.shtml, parse it, and then replace the above directive with the parsing results of header.shtml, which in turn, contains some directives to follow. In the first example, however, the header.txt is not parsed for SSI directives, because it has no .shtml extension. The web server simply read the content in a verbatim manner and put them in the place of the directive including header.txt.

In addition to the SSI pages of kavoir.com, more complete and authoritative resources can be found at apache.org.

»Post a Comment

0 Comments:

»Post a Comment

Links to this post:

Create a Link

« Home