Home arrow HTML arrow Page 3 - Using SSI to Boost Efficiency
HTML

Using SSI to Boost Efficiency


Have you always thought Server Side Includes (SSI) was too complex? Check out Clay Dowling's tips as he explains some simple SSI directives and how to simplify managing navigation menus.

Author Info:
By: Clay Dowling
Rating: 4 stars4 stars4 stars4 stars4 stars / 9
August 16, 2004
TABLE OF CONTENTS:
  1. · Using SSI to Boost Efficiency
  2. · Enabling SSI
  3. · Simple SSI Directives
  4. · How to Use SSI
  5. · Navigation Menus
  6. · Common HTML Blocks
  7. · Business Considerations

print this article
SEARCH DEVARTICLES

Using SSI to Boost Efficiency - Simple SSI Directives
(Page 3 of 7 )

As the name implies, SSI allows a web designer to insert the contents of one file into another when the file is served up. Other information can also be inserted, including file modification dates, file sizes and values of server environment variables. The general form of all directives is:

<!--#element attribute=value attribute=value ... -->

Because it's wrapped in a comment, if your server isn't configured to support SSI, the content will be exported normally and your browser will treat it just like any other HTML comment. If you're using a syntax checking editor, this will prevent it from choking on your directive.

Including Files

To include one file in the output of another, use the #include directive:

<!--#include virtual="/virtual/url/to/file" -->

If you've used SSI before or if your working on IIS, the "virtual" attribute may look a little funny to you. It isn't the file system path to a file but is a URL on the local server to the file. This makes your SSI files easier to move around on the file system and from server to server.  The "file" attribute is still supported but "virtual" is greatly preferred.  If you persist in using "file", you may run into trouble when you move your site from the development server to production.

File Modification Time

File modification times are useful when you're offering files for download. When the new file is uploaded to the server, the web page will automatically reflect the new modification time.

<!--#flastmod file="download.zip" -->

This directive can also be used to mark a page with its own last modification date by including the file name as the "file" directive.  While there are other ways to handle this, such as a version control system, it's a pretty good work around for providing the information.

Executing Commands

The output of programs run on the server can also be included.  The classic example is to produce a file listing.  I've also used it for web page counters and for generating dynamic menus on my web site.

<!--#exec cmd="menu.pl" -->

The command is executed in the system's default shell and inherits all of the environment variables available to a CGI program. This feature is potentially very dangerous and should be disabled site wide if users can contribute content to the web site, such as via a guest book.  For Apache, adding IncludeNOEXEC to the Options directive where you enabled SSI. For IIS, the feature is disabled by default and must be turned on.

Displaying Environment Variables

You can display any environment variable using the following directive:

<!--#echo var="variable" -->

It's useful for displaying any of the variables which are available to CGI programs.

Setting Environment Variables

It's useful to be able to set environment variables. You can use it to set certain options in CGI programs called by the #exec directive. You can also set variables in one file that are displayed in another included file using the #echo directive.

<!--#set var="name" value="value" -->

Unfortunately you can't use this feature on IIS.  That means one of the examples coming up won't be useful for IIS users.


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials