By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Placing Common HTML Code In A "Common" File

P: n/a
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.

Anyone ever do this and if so how?
An example would be Great!

Thanks in advance.

Hugs
Sherry
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

P: n/a
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

Jul 20 '05 #3

P: n/a
Sherry Littletree wrote:
I am working on a site that has a large amount of common html on all its
web pages.
Generally if there is a _large_ amount, its caused by the use of too much
presentational markup. Move your presentation to an external style sheet
file instead.

However, even that will leave some elements you may with to have in common
on each page (such as navigation).
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.


http://www.allmyfaqs.com/faq.pl?Incl...ile_in_another

--
David Dorward http://dorward.me.uk/
Jul 20 '05 #4

P: n/a
Here are two reasons why I cjhose NOT to use SSI as a method to do including
of common modules;
DRAWBACK #!: The use of SSI will make it neartly imposible to do simple
WSYWIG trial and ewrror development work.
DRAWBACK #2: the use of SSI requires the extension of the files to be .shtml
or such. This makes other local authoring tools crap on you, like FrontPage
does.

I chose to use FrontPage as the method to do includes of commong dodules in
a WSYWIG authoring environment on my loac PC where I could test and develop
in a trial_and_error method.

I suspect there are other tools out there besides FrontPage that will do
this without forcing you to rename the extensions and without giving up
local testing. But, I do not know what they are.

"David Dorward" <do*****@yahoo.com> wrote in message
news:bo*******************@news.demon.co.uk...
Sherry Littletree wrote:
I am working on a site that has a large amount of common html on all its
web pages.


Generally if there is a _large_ amount, its caused by the use of too much
presentational markup. Move your presentation to an external style sheet
file instead.

However, even that will leave some elements you may with to have in common
on each page (such as navigation).
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.


http://www.allmyfaqs.com/faq.pl?Incl...ile_in_another

--
David Dorward http://dorward.me.uk/

Jul 20 '05 #5

P: n/a
> DRAWBACK #2: the use of SSI requires the extension of the files to
be .shtml
or such.


The use of .shtml is typically just a server default and where SSIs
are the rule rather than the exception the server can usefully be
directed to parse .html and .htm too. Of course you may not have this
degree of access to the server configuration.

Jul 20 '05 #6

P: n/a
news frontiernet.net wrote:

Maybe you (what a funny name you have BTW) should read:
http://www.allmyfaqs.com/faq.pl?How_to_post
Here are two reasons why I cjhose NOT to use SSI as a method to do
including of common modules;
DRAWBACK #!: The use of SSI will make it neartly imposible to do simple
WSYWIG trial and ewrror development work.
WRONG!

Leaving aside the non-existance of WYSIWYG editors for the web, and the
general poor quality of those editor which claim to be WYSIWYG (but are
really just graphical HTML/CSS generators) -

* If you are doing trial and error development work, you can build your
template and then rip it apart to use for SSI

* A number of generators can emulate SSI during the design process
DRAWBACK #2: the use of SSI requires the extension of the files to be
.shtml or such.


WRONG!

See the second link in the section on SSI at the page:
http://www.allmyfaqs.com/faq.pl?Incl...ile_in_another

.... and of course the server could be configured to use whatever extension
you want (if you don't want to use the XBitHack).

--
David Dorward http://dorward.me.uk/
Jul 20 '05 #7

P: n/a

In article <gF****************@newsread1.news.pas.earthlink.n et>,
"Sherry Littletree" <en******@encryted.org> writes:

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.


PHP is easier to use than SSI and much more powerful. Any server-
side approach is better than javascript because server-side
processing will work even if the client disables active scripting/
javascript.
--

Warren S. Sarle SAS Institute Inc. The opinions expressed here
sa****@unx.sas.com SAS Campus Drive are mine and not necessarily
(919) 677-8000 Cary, NC 27513, USA those of SAS Institute.
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.