Sherry Littletree wrote:
Hi All
I am working on a site that has a large amount of common html on all its web
pages.
I am looking for a way to place this in a single file so, if changes are
made, I can change this single file and do not have to change each and every
page.
I have the Java scripting in a common .Js file but have not been able to
find a way to do this with my html content.
(NB: properly, "javascripting", not "Java scripting", since Java and
javascript are completely separate languages.)
Anyone ever do this and if so how?
An example would be Great!
There are two things that come to my mind right away:
1. Create a javascript file that will (contain functions that)
document.write the common HTML
2. Use Server-Side Includes (SSI) (I use this technique on my intranet)
Each has advantages and disadvantages:
For 1:
Advantages:
A. Requires no special server configuration
B. Lets you deliver the common markup packaged as javascript (and since
you're asking in a javascript group, I assume this is comfortable to you)
Disadvantages:
The material written by javascript will be completely unavailable to
anyone whose browser has js unavailable for any reason (non-existent,
disabled, etc). This seriously breaks your pages.
For 2:
Advantages:
A. Common content can be placed in files that contain HTML that would
otherwise be written into the main HTML file. Any such common HTML file
is designated to be included by a Server-Side Includes directive such as:
<!--#include file="location/file.ext" --> or
<!--#include virtual="url/file.ext" -->
Trivial example:
<html>
<head><title>Trivial SSI Example</title></head>
<body>
<!--#include file="PageHeader.html" -->
<br>
My unique page content
<br>
<!--#include file="PageFooter.html -->
</body>
</html>
PageHeader.html:
<h1>Page Header</h1>
PageFooter.html:
<p>Brought to you by SSI!</p>
Output might be rendered as:
Page Header
My other page content
Brought to you by SSI!
B. No reliance on javascript or other client-side active scripting. All
SSI processing takes place (obviously :-) ) at the server.
Disadvantages:
A. Server must be configured to support Server-Side Includes. Usually
this also means that the main HTML file (i.e., any HTML file containing
SSI directives) must be given a special extension such as ".shtml" (the
customary one, usually read as "server-parsed" HTML).
B. This requires more processing by the web server, which has to read
the content of the file being served, looking for the SSI directives and
following the indicated instructions.
Google for "server-side includes" for additional info. There should be lots.
Regards,
Stephen