Motive [Home].Glossary.

Guides

The Motive Web Design Glossary

server-side include (SSI)

A server-side include is code that is added to a webpage file before it is downloaded.

The code that is added could be a date stamp, metadata records, navigation, etc.

Streamlining website maintenance

Include files are often used to simplify website maintenance, as changing a single include file will ‘update’ every page that references the include.

For example, every page in the Motive Web Design Glossary has the same masthead at the top of the page. The top row of buttons, the ‘Motive Glossary’ title, and the search box are all stored in a single include file. If we were to add a new section to the website, we could simply update the glossary masthead include file and a link to that new section would instantly be added to every page of the glossary.

Setting-up a server to use server-side includes

For server-side includes to work, the server must be instructed to process (parse) a webpage before it is downloaded. To determine if a file should be parsed, the server checks the file extension. For example, the Apache web-server is typically configured to parse files ending in.shtml. Apache can be instructed to parse files with other extensions by using an .htaccess file.

Configuring Apache for server-side includes

To enable Apache to parse server-side includes the server behaviour can be modified using an .htaccess file.

Important notes on .htaccess files

  • An .htaccess file placed in the root-directory of a website will change server behaviour website-wide (unless over-ridden by an .htaccess file at a lower level of the website structure).
  • Before uploading, check for an existing .htaccess file.
    As an .htaccess file can also be used to set security directives, copying a new file over the old could remove password protection.
  • The server/host must allow local .htaccess files.
    Local .htaccess files contain instructions (directives) that modify the operation (behaviour) of the server, on a directory-by-directory basis.
  • The .htaccess parsing directive instructs the server to parse all files with the specified file extension(s). This can affect the time it takes for a webpage to download. The delay is typically minimal but will varying depending on the number of simultaneous connections, the speed of the server, etc.

To enable Apache to parse server-side includes for files ending in both .htm and .html:

  1. Copy the code below into a text editor (e.g. Notepad or Simpletext).

AddType text/x-server-parsed-html .html AddType text/x-server-parsed-html .htm

  1. Save the file with the name .htaccess (dot h-t-access).
  2. Upload to the root directory of the website.

Troubleshooting server-side includes

Linking to webpages and images from include code

The process of parsing the parent webpage does not change/update the code contained in the included file. If this code links to webpages or images, the link path should be specified in relation to the location of the parent webpage (and not the location of the include file). If a single include is used at a number of directory-levels, then the path should be specified relative to the site root.

Server-side includes and server-side scripting languages

Webpages are often created using server-side scripting languages such as ASP or PHP. As webpages can only be processed once before download, a server-side include must be created using the web-server directive or the appropriate scripting language directive, i.e. a webpage cannot contain both a web-server include directive and a server-side scripting language include directive.

Related terms: client-side/server-side, links: absolute, relative, root-relative, MIME-type

 

Motive Web Design Glossary Trivia