Web Publishing Secrets:SSIs
The Basics
The idea behind Server Side Includes (SSIs) is simple: each include (short for “included item”) is a separate file that another HTML file or template calls (or references) by file name. Every time the HTML code calls the included item, the server storing the Web pages inserts the include into the referencing file. The Web surfer sees a single, complete page, not the components that make up the page behind the scenes. But the discrete code files let you separate a page’s structure from its unique content, and such separation makes it easy to expand your Web site without having to perform tedious manual updates of individual pages.
Say the navigation bar on your site changes frequently. If the navigation bar is an include, you simply open that one file (we’ll call it “navbar.html”) and update it, and every page on your site will display the new navigation bar.
Although this include has a html file extension, it’s not a complete HTML file; it’s a fragment lacking the html, head, and body tags. That’s because this include will be within another document that already has those required tags. (Note than an includes file extension must match your server’s configuration. For example, I once worked on a Web site where all SSIs had the extension htf to set them apart from standard HTML files.)
Someone viewing index.html in a browser sees a complete HTML document-including the current version of the navigation bar.
Putting the Pages Together Again
You can put SSIs to work for you in many ways. The easiest is to convert the individual components of a template (navigation, site ID, content, page color, and so on) into separate includes and then combine the includes to make up individual pages.
The following sample page is only 12 lines of codeand not one of those lines deals with page layout or content. Instead, each part of the page is called from a separate include and assembled before the server pushes it live.
Haste Makes Waste
Before you rush to begin designing and implementing pages based on SSIs, make sure that a few things are in place.
- Your Server Supports SSIs Several Web servers permit SSIs for Web-page assembly. One of the most popular is Apache Web server. (For more information about Apache, see Mac OS X Secrets, August 2001.) If you aren’t running your own server, ask whether the host server allows SSIs.
- You Can Test Live Pages Because this site-building technique requires a server, you need a staging area to preview and tweak your site before pushing it live. If you run Mac OS X, you can preview sites with includes locally. In OS 9 and earlier, you can use Personal Web Sharing for the local preview. Of course, if you have your own server, you can create a separate staging area on it.
Good for Web Sites Great and Small
SSI provides a flexible framework that lets you control the smallest elements in your page and manage the contents and appearance of your site on a grand scale. It’s truly an elegant solution to one of Web design’s most vexing problems.
(C) 2002 Macworld. via ProQuest Information and Learning Company; All Rights Reserved
This article was last modified on January 8, 2023
This article was first published on January 2, 2002
