Michael Doran Home Page
Contact | Site Map | Search  
  Home > Archives > Server Side Includes

Server Side Includes

Introduction

Introduction | Examples | Templates | Server Setup
This presentation was prepared for a meeting of the UTA Web Developers group. The focus is on using SSI for site management in a Unix/Apache environment.

What are Server Side Includes?

A Server Side Include is an instruction, embedded within a web page, that tells the web server to perform a task. The task is performed prior to the server returning data in response to a browser request.

What can Server Side Includes do?

Server Side Includes can tell the web server to:
  1. Insert "boilerplate" text and/or HTML code into a web page
  2. Execute an external command or program from within a page
    • CGI programs
    • operating system commands
  3. Echo a web server environment variable
It may help to look at some examples.

How do Server Side Includes work?

When a browser requests a page, the web server must parse the web page in order to look for any SSI instructions. The web server then performs the task before returning the page to a browser. The Apache web server, as installed, is ready to process Server Side Includes; it merely requires a few lines of configuration in the start up file.

Site Management

One of the most important uses of SSI is as a method for helping to build a scalable web site. A scalable web site is one that is as easy to maintain as it grows to hundreds or thousands of pages of content as it did when it was only two or three pages of content.

The secret is to create standardized headers and footers containing the HTML code that is common to every page on your site. These headers and footers can then be included in pages via SSI directives. Using SSI for this purpose requires no specialized techno-geek knowledge nor programming skills, and can be illustrated by examining the template used for these pages.

Other strategies for scalable web sites either involve a lot of money or a very steep learning curve. (Usually both!) Examples are content management systems and database backed web sites. Using SSI is a way to achieve similar results on a shoestring and it can be implemented by anyone who is capable of writing basic HTML code. In addition, SSI is a great way to get your feet wet in database backed pages without having to make a commitment to a full-blown system.

If SSI is so great (and easy), how come I'm not more aware of it?

Web developers tend to co-opt techniques and technologies used at sites they admire. Typically, they do this by "viewing" the source code in order to see how a site was constructed. Unfortunately, that doesn't work for SSI, because the source code shows us the results of SSI rather than the SSI code that produced the results.

The fact is, many sites do use SSI even if we don't realize it! Unlike most other technologies for dynamic web pages (for example, CSS or JavaScript), the use of SSI by other sites is invisible to the inquisitive web developer. (The exception to this is in those cases where an SSI fails and we see an error message.)

Additional Resources