|
An SSI (Server Side Include) allows you to
include content that is reused on many pages by updating
the content one time. It's also a way to have dynamic
content on your pages without updating the HTML code
or using FTP.
"Using Server Side Includes is a technique where by you can insert the content of one file into other files." - YourHTMLSOurce.com.
Basically, and include is a piece of content — e.g. navigation links, a local footer, a header — that you want to appear on many pages. Instead of having to put that piece of content on all those pages, and then update each of those pages when you need to update that content, you update the content once and then all the pages that include that content will be updated.
What's that you say? As a Webmaster,
you can divide your page into parts. For example, these
might be: header, navigation bar, content well, text
insert, site footer, and copyright footer. The parts
that you want to appear on several pages on your site, like the header, navigation
bar, and footers can be stored separately as text files
and imported dynamically into all the pages where they
are used.
As you update the content well (that piece
which changes frequently) or any other piece, the browser
assembles the parts dynamically, and the page is displayed
to the site visitor as if the page had been created
as a single unit. In fact, when you look at the source
code from the browser window, it's a seamless unit.
The "magic wand" that "glues" the pieces together
is an SSI.
"The simplest kind of SSI is a virtual include, which can use one command to pull HTML fragments, such as navigation bars, into all the pages of a site without having to hand code each page." - Webmonkey
The advantage of using a
server side include in
a page is that the browser
builds the page using the
latest version of the
included file and dynamically
updates all the pages
using that piece of content
the next time the pages
are refreshed or loaded
by the browser. Thus, blocks
of content that are reused
on many pages only have
to be updated once. SSI
use can work like frames,
without the disadvantages
of using a framed site.
Using SSI's is a good way to place
headings, navigation elements, as well as local and
site-wide footers in a web page.
The Publishing
Tools provides by Web Services (News
Box Publisher, Tool Central NewsPublisher, Calendar
Box Publisher, and DirectoryBox all use includes.
Note:
MCPS servers DO NOT support
SSI execs that execute a
program on the server because
they pose a high security
risk to our servers.
The format of the server side include of text is one
line of code:
<!-- #include file="filename.txt" -->
or
<!-- #include virtual="/directory/filename.txt" -->
That's it. One line of code tells
the browser "go get this file and insert it here."
However,
you have to remember that
this file will appear on
many pages that could possibley
"live" in many different
folders. So you must be sure
that the path to include
the file directs the page
to the correct folder.
It can't be that easy, can it? Well, there are a couple
of other little things you need to do once for each
page. You must use the file extension .shtm or .shtml
instead of .htm and .html.
This is simply a naming convention
that says "This html file includes Server commands -
please parse it before delivering to the browser site"
(hence the "s"). (Parsing is skipped for
all "plain" .html [or .htm] files.) Shtml is the default
extension for a page with server-side includes.
The last thing you need to
do is send people to the
new page(s). For example
if you updated your home
page so that it uses SSI,
you're actually changing
your page name from index.html
to index.shtm. If you delete
the old index.html and
put up index.shtm, your
new page is the default.
It displays in the browser
when your directory is
opened and everybody's
happy. Few will even notice
that the page name has
changed.
But,
if a visitor has bookmarked
or linked to the page
named index.html, and
they use their bookmark
or link to return to your
page, it won't be there
anymore. The site visitor
will see "404 —
Page not found."
What
can you do so you don't
lose this site visitor?
You can make a redirect
page to send those seeking
the old index.html and
forward them to your new
page now named index.shtm.
An example of this code
is included in How
to Make and Use a Redirect.
It's good practice to put
up a redirect to replace
the old index.html to avoid
frustrating your site
visitors.
The content pieces that are
in your includes are made
in the same way you make
your pages. The pieces,
though, only contain their
part of the page. You should
not include any <html>, <head> or <body>
tags as you need for a complete
page.
You can preview your "piece" in
your HTML editor the same
way you'd preview an .html
page. To make the piece into
an includable file, save
it as a text file. Give it
an identifiable name with
the suffix of .txt ( i.e.
footer.txt) and save it
in the appropriate folder.
You'll need one text file
for each include command
in your web page.
To learn more about server side includes see the following
sites.
For questions on using SSI's, contact the Web Services
Team at webmaster@mcpsmd.org
or post questions to the Webmasters Conference on Outloook..
For additional information on
how to implement SSI tags, view Appendix
A in our SSI help document (311K PDF).
|