Search

How to Update Your Web Site Using Server Side Includes (SSI)

0 views

Understanding Server Side Includes

Server Side Includes, or SSI, are a lightweight scripting technique that lets you pull a single file into multiple web pages at the time the page is served. Think of it as a template system that lives on the server instead of the client. When a browser requests a page, the web server scans the file for SSI directives, replaces them with the contents of the referenced file, and then delivers the finished HTML to the visitor. Because the server does the replacement before the page leaves the host, the user never sees the include syntax, only the final rendered page.

SSI shines when you need a consistent look and feel across a large number of pages. Headers, footers, navigation menus, or even reusable blocks of content such as legal notices or promotional banners can be stored in a single file. When you edit that file once, every page that references it updates automatically. The time and effort saved on a site with hundreds of pages is immense – from minutes to hours.

The beauty of SSI lies in its simplicity. Unlike full-blown server-side programming languages, you don't have to write loops, conditionals, or database queries. All you need is a plain text file, a little marker in your HTML, and a server that recognizes the SSI syntax. Most shared hosting plans, especially those running Apache, Nginx, or Microsoft IIS, support SSI out of the box. If you’re unsure, just check your hosting control panel or contact support.

There are two common SSI directives: #include and #exec. #include pulls in the content of a file, while #exec runs a shell command and injects the output. For navigation menus, #include is the usual choice because it guarantees the same HTML on every page. The syntax is simple: <!--#include virtual="/includes/nav.htm" -->. The virtual keyword tells the server to treat the path relative to the site root, making the directive portable across subdirectories.

Because SSI runs before the page is served, you can also use it to conditionally show content based on environment variables. For instance, you might display a banner only in a staging environment by checking the REQUEST_URI variable. However, for most small to medium sites, a straightforward include suffices.

Performance is another benefit. The server does the replacement once per request, so the delivered HTML is static from the client’s perspective. There is no extra processing required on the client side, and caching mechanisms such as Varnish or CDN edge caches can still cache the final page without noticing the include step.

In sum, SSI is a simple, efficient way to maintain shared components across a website. It requires minimal configuration, works on almost any server, and eliminates repetitive manual edits. The next section walks through setting up a drop‑down navigation bar that updates across your entire site with a single file change.

Implementing SSI for a Site‑wide Navigation Bar

Start by verifying that your hosting environment accepts SSI directives. Most Apache setups need the AddType text/html .shtml directive and the Options +Includes flag in the .htaccess file. If you’re on Nginx, the equivalent is ssi on; in the server block. Once the server is ready, you can create a folder named includes in your site’s root directory. This folder will hold all reusable snippets.

Inside the includes folder, create a new file called nav.htm. The content of this file should be just the markup for your navigation menu, nothing more. If you copy code from an existing page, strip away the <html>, <head>, and <body> tags. Keep only the <nav> element or a <ul> list with links. This keeps the snippet clean and portable. If you want a drop‑down menu, use CSS to style it. Store any associated CSS in the same includes folder, for example menu.css

Next, make sure that any JavaScript needed for the menu is also placed in the includes directory. A common choice is virtualmenu.js. Reference the script and stylesheet in the <head> of your master layout page. Use relative paths so the files are always found regardless of the page’s location. For example: <link rel="stylesheet" href="/includes/menu.css"> and <script src="/includes/virtualmenu.js"></script>

With the assets in place, it’s time to insert the SSI directive into each page that should display the menu. Locate the spot where the navigation bar should appear – typically right after the opening <body> tag. Paste the following line: <!--#include virtual="/includes/nav.htm" -->. That single line tells the server to fetch the contents of nav.htm and splice them into the page at that point. You can place the directive in a template file if your site already uses one; otherwise, repeat it on every page.

Because the server only processes SSI directives in files with the .shtml extension, you need to rename your pages accordingly. If your site currently uses .html or .htm files, change each to .shtml. This can be done manually or via a bulk rename script. The renaming step is crucial – without it, the server will treat the directive as plain text and deliver it unchanged to browsers.

Upload the entire includes folder, the modified pages, and any updated CSS or JS files to your server using FTP or a file manager in your hosting control panel. After the upload completes, open one of the pages in a browser. If the SSI syntax is working, you should see your drop‑down navigation rendered. If you see the raw directive, double‑check the file extension and the server’s SSI configuration.

Now, suppose you want to change the appearance of the navigation bar – maybe adjust the font, add a new link, or change the color scheme. All you have to do is edit nav.htm, upload it, and the changes will instantly appear on every page that includes it. The same applies to menu.css or virtualmenu.js; edit the file, upload, and the effect is global. This single-file update mechanism saves time and eliminates the risk of inconsistent markup across thousands of pages.

There are a few best practices to keep in mind. First, keep nav.htm lean: only include the HTML for the menu, not full page structure. Second, use descriptive IDs or classes so the CSS targets only the navigation elements. Third, test the site in multiple browsers to ensure the drop‑down works on older versions and on mobile devices. Finally, back up your includes folder before making sweeping changes – a quick copy ensures you can revert if something goes wrong.

By following these steps, you’ve replaced hundreds of manual edits with a single, maintainable file. The result is a site that updates instantly, stays consistent, and is easier to manage as it grows.

Tools and Resources for Working with SSI

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!

Related Articles