Server Side Includes (SSI)

It is commonly known that one can make web pages dynamic and add on-the-fly customization by running scripts on the web server. While script driven solutions certainly have their place, the fact that running a server-side script involves running an external application on the server places a significant additional burden on server resources. Server Side Includes, SSI, offer an elegant alternative which does not impose this burden. Unlike scripting languages which operate courtesy of the Common Gateway Interface, most web servers have an innate understanding of SSI Directives which can make their execution measurably faster.

You can find a thorough introduction to all aspects of SSI here. The most commonly used SSI directive is #include. You will have noticed that every page on this site has a menubar running down the left hand side of the window. The anchors and comboboxes in this bar ensure that the user is never more than one or two clicks away from the information he/she is seeking. Logic and efficiency both demand that the sourcecode for the menubar be written just the once and then somehow "stitched" into each webpage just before it is delivered to the user. This is accomplished by dint of using the simple SSI directive

<!--#include virtual="/en/includes/logo.html" -->

and using the extension .SHTML for this HTML page. The SHTML file extension acts as a directive to the web server to process #includes before serving up the page to the user. The logo.html file contains the actual code for the toolbar. In the event, unlikely, that this page is served up by a server which does not understand SSI, or that the server has SSI processing disabled (possible) the <!--#include... line makes it all the way to the user's web browser which treats it as a normal HTML comment and ignores it. The user ends up seeking a partially correct web page but total disaster is averted.

virtual indicates that logo.html is located on the web server but not necessarily under the server root. Web servers can be very picky when it comes to correct SSI syntax so pay very close attention to your use of spaces and the solidus, /, character. In particular note, that the virtual path specification begins with a /!

Most hosting services require the use of the .SHTML extension for resources to be subjected to SSI processing before being served up. Nevertheless, it is worth checking with the hosting service you plan to use before creating hundreds of pages with the SHTML extension.

Jump To...

Colophon