Server-Side Includes
Even though you can’t write a web application on your own, you can borrow a few tricks from the web applications model—if your web host supports them. The simplest example is a technology called server-side includes (SSIs), which is a scaled-down version of the HTML-assembling trick used on sites like Amazon and Expedia.
Essentially, a server-side include is an instruction that tells a web server to insert the contents of one HTML file into another. For example, imagine you want to use the same menu on several pages. You would begin by saving the menu as a separate file, which you could name menu.htm. Here are its contents:
<h1>Menu</h1> <a href="...">Page 1</a><br /> <a href="...">Page 2</a><br /> <a href="...">Page 3</a><br /> <a href="...">The End</a>
Notice that menu.htm isn’t a complete HTML document. It lacks elements like <html>, <head>, and <body>. That’s because menu.htm is a building block that you embed in other, full-fledged HTML pages.
Now you’re ready to use the menu in a web page. To do that, you add a specialized include command to the page where you want the menu to appear. Here’s what it looks like:
<!--#include file="menu.htm" -->
The Include command disguises itself as an HTML comment (Where Are All the Pictures?) using the <!-- characters at the beginning of the line and the --> characters at the end. But its core tells the real story. The number sign (#) indicates that this command is actually an instruction for the web server, and the file
Get Creating a Website: The Missing Manual, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.