How Using 'Server Side Includes' Makes Site Maintenance Easier

October 24, 2013

Using Server Side Includes (SSIs) is a simple, but very effective, way to provide dynamic features on your web pages.

Many dynamic pages are generated by using scripts on either the client or the server. To implement scripts, knowledge of a scripting language, like JavaScript or PHP, is required. But SSIs can be simple text, images, or HTML files that are included in a page before it is returned to the browser.

To determine whether or not your website might benefit from SSIs, look at your pages and identify what elements on them are common to all, or most, of the pages.

For example, many websites will display the company logo on all pages. Likewise, the main navigation bar on a website is usually carried on all pages.

Similarly, a lot of websites carry advertising on many of the site's pages. The logo, navigation bar, and advertising blocks are prime candidates to be placed in SSIs.

Examples

  • Let's take a look at how having the navigation bar in an SSI can make site maintenance a lot easier. Your website has been live for some time and you have received a lot of questions from visitors. You notice that the same questions keep cropping up, and you decide to add a Frequently Asked Questions (FAQ) page. You want to place the link to your FAQ page in the main navigation bar. If the HTML code to display the navigation bar is embedded in each page on your site, you will have to change every single page to display the new FAQ link. But if the navigation bar code is contained in an SSI, you need to change just the SSI file. Once that's done, every page that uses the SSI will immediately display the new link.
  • If your site carries advertising served up by third-party companies, you can use SSIs very effectively to compare and contrast ad performance. By placing the scripts provided by the advertising companies in SSIs, instead of directly in your web pages, you can easily swap between different companies' ads, without having to upload different versions of your web pages. This level of control gives you the ability to monitor the performance of the different ads over any chosen timescale.

How to use an SSI in a web page

Using SSIs is very straightforward. All you need to do is insert a include command in the page where you want the included file to appear. The following example tells the server to include the file 'menu.txt' in the page:

<?php include("folder/menu.php"); ?>

If the file you want to include is located in the same folder as the web page, you can use this format:

<?php include("menu.php"); ?>

Testing your SSI

.

After inserting an SSI, you should always load the page to make sure it displays correctly. If your SSI contains unmatched tags, the display of the entire page can be corrupted.

Likewise, if your included file is an image, or a CSS division with the width attribute set, you need to make sure the inclusion does not push other page elements out of place.

by on October 24, 2013

HAVE AN IDEA? INTERESTED IN WORKING WITH US ON A PROJECT?
e-dimensionz Inc is a web development company based in Kitchener-Waterloo
specializing in custom websites, CMS frameworks, mobile applications, and Open Source technology
e-dimensionz Inc, 888-635-9679, info [@] e-dimensionz.com