Simplifying your site with Server Side Includes

Inclusion

© Phaif, 123RF

Author(s):

Server Side Includes (SSIs) can save you time and make your website easier to maintain.

Most websites have a handful of elements that are common to all or most pages, such as headers, footers, and menus. Hard-coding these sections into each page means that if you ever make any changes, you have to edit every single page, which is very tedious and not a good use of your time. Server Side Includes (SSIs) are an easy way of writing HTML snippets once only and then including them in your pages with a single reference.

Writing the Include File

Before setting up the web server to handle SSIs, I'll start by defining some SSI content. Listing 1 shows a basic footer include file, containing just the footer information I want at the bottom of each page. (The styling is all in the CSS, which I'm not showing here – this is just the HTML logic. It is always good practice to separate content logic from presentation and styling.)

Listing 1

Basic Footer Include File footer.html

01 <div id="footer">
02   <p><a href="mailto:webadmin@mysite.com">website contact</a></p>
03   <p><a href="http://www.mysite.com">return to homepage</a></p>
04 </div>

[...]

comments powered by Disqus

Direct Download

Read full article as PDF:

News