How to include boilerplate (headers, footers) in web pages.

N

news.rcn.com

I want to include static features in all pages of a web site- things like
banners, main menus, etc. - and would like some help in what is the
'standard' way(s) to do this.
I've done this before using Java Server pages which have an include
directive but JSP is not an option.

It appears that server side includes (SSI) and scripting (CGI) are the
options. (JSP and ASP are not available from the web host). Is there
another approach?

It seems overkill to make every page on the site a script when most pages
are static but I don't want to have copies of the boilerplate that have to
be maintained in every file.

Thanks in advance for your advice.

jim
 
J

jcsnippets.atspace.com

news.rcn.com said:
I want to include static features in all pages of a web site- things like
banners, main menus, etc. - and would like some help in what is the
'standard' way(s) to do this.
I've done this before using Java Server pages which have an include
directive but JSP is not an option.

It appears that server side includes (SSI) and scripting (CGI) are the
options. (JSP and ASP are not available from the web host). Is there
another approach?

It seems overkill to make every page on the site a script when most pages
are static but I don't want to have copies of the boilerplate that have to
be maintained in every file.

Thanks in advance for your advice.

jim

Hi Jim,

Maybe this can help you - it's a tool I've written a while ago to simulate
the behaviour of SSI. I've just put it online.
http://jcsnippets.atspace.com/java/htmlssi.html

Best regards,

JC
 
R

Raymond DeCampo

news.rcn.com said:
I want to include static features in all pages of a web site- things like
banners, main menus, etc. - and would like some help in what is the
'standard' way(s) to do this.
I've done this before using Java Server pages which have an include
directive but JSP is not an option.

It appears that server side includes (SSI) and scripting (CGI) are the
options. (JSP and ASP are not available from the web host). Is there
another approach?

It seems overkill to make every page on the site a script when most pages
are static but I don't want to have copies of the boilerplate that have to
be maintained in every file.

You might try pre-generating the static files with the headers and
footers. Roedy Green who posts here often has a tool for this I believe.

HTH,
Ray
 
R

Roedy Green

You might try pre-generating the static files with the headers and
footers. Roedy Green who posts here often has a tool for this I believe

I have system for generating a website statically. . It has a number
of parts.

1. macro expansion. You write the macros in Java. You can look on my
website and see what some of them can do. It is nice having the full
power of java to do file i/o and other thing you could imagine. Search
for the word "macro". I can so some SSI-like stuff like file date and
size inclusion. There is a nestable include macro. I can't do hit
counts, at least not up-to-date ones. Macros that save me a lot of
time are Image that inserts the width and height automatically.
headers and footers that are quite clever, and of course nicely
encapsulated. You just change the say the copyright display method and
bang tho whole site is fixed. Book Refer generate links to muliple
bookstores. Links about Java versions, directories, JavaDoc and
filenames all automatically kick over when a new Sun version comes
out. I can do all the same things you can in JSP, with the
restriction I have to have the data at Upload time. I can't wait for
the user to tell me something.

2. compression. It remove excess whitespace from the HTML to speed
downloads. Someday I might take it a step futher and remove all
comments and the macro original text too.

3. index generation. I have various glossaries and it builds master
and letter level index pages.

4. Untouching. This redates files back to what they used to be if
they have not really changed. It gets rid of any spurious updates to
avoid uploads.

5. JDisplay with preprocessse listings to colourise them and embed
them either as applets or HTML. It can handle HTML, XML, Java, SQL,
BAT, ini, csv, properties etc. It has robust parsers that can handle
fragments and bad code.

6. replicator. Allows people to maintain an up to date mirror with
minimal downloading.


I have used this myself gradually improving it over the years not
worrying to much about generality.

I have not published it. If someone is interested, I can get around
to packaging it up. It requires a Java programmer to use, since you
need to write or modify the macros for your own site.

Why bother? why not use JSP? You have no budget. You don't have
access to a powerful enough JSP server to generate content
dynamically. This all works with a vanilla HTTP server with FTP
upload.

The other reason is you want to generate content to be read offline.
JSP can't do that. You can distribute your website on CD and it is
readable.
 
T

Tim B

news.rcn.com said:
I want to include static features in all pages of a web site- things like
banners, main menus, etc. - and would like some help in what is the
'standard' way(s) to do this.
I've done this before using Java Server pages which have an include
directive but JSP is not an option.

It appears that server side includes (SSI) and scripting (CGI) are the
options. (JSP and ASP are not available from the web host). Is there
another approach?

It seems overkill to make every page on the site a script when most pages
are static but I don't want to have copies of the boilerplate that have to
be maintained in every file.

Thanks in advance for your advice.

jim

You could create a javascript file with functions that return the html for a
banner, menu, etc. Include a reference to this file in each html page, plus
appropriately id'ed div tags. Then in a javascript block set the innerHTML
value of each div to the value returned by the corresponding function. This
block must be after the last div being set.

advantage: banner and menu html in one file only.
disadvantage: site will be unusable without javascript, plus it's maybe a
bit hokey.

Personally, I'd just get a different web host that supports jsp
 
R

Raymond DeCampo

Roedy said:
You might try pre-generating the static files with the headers and
footers. Roedy Green who posts here often has a tool for this I believe


I have system for generating a website statically. . It has a number
of parts.

[snip]


Why bother? why not use JSP? You have no budget. You don't have
access to a powerful enough JSP server to generate content
dynamically. This all works with a vanilla HTTP server with FTP
upload.

The other reason is you want to generate content to be read offline.
JSP can't do that. You can distribute your website on CD and it is
readable.

Roedy,

Another good reason is that by pre-generating the files once, you save
the cost of having to generate the response every time with a dynamic
technology like JSP. If the pages are static, there is no point to
building them over and over again...

Ray
 
R

Roedy Green

Roedy,

Another good reason is that by pre-generating the files once, you save
the cost of having to generate the response every time with a dynamic
technology like JSP. If the pages are static, there is no point to
building them over and over again...

That's what I was hinting at with the "powerful enough JSP server". I
obviouly takes a lot more work on your server's part to do dynamic
generation. With my scheme, all the server has to do is hand the file
out without processing. If generated files are absolulely identical
for a while, then they can be better cached at various levels. If you
regenerate each time, each one is considered unique and can't very
well be cached anywhere.

I am working up a Java glossary entry to explain this.

IT will be called http://mindprod.com/jgloss/htmlstaticmacros.html
 
R

Roedy Green

That's what I was hinting at with the "powerful enough JSP server". I
obviouly takes a lot more work on your server's part to do dynamic
generation. With my scheme, all the server has to do is hand the file
out without processing. If generated files are absolulely identical
for a while, then they can be better cached at various levels. If you
regenerate each time, each one is considered unique and can't very
well be cached anywhere.

I am working up a Java glossary entry to explain this.

IT will be called http://mindprod.com/jgloss/htmlstaticmacros.html

It is now posted. Whew. A lot more work than I thought it would be.
 
R

Roedy Green

Another good reason is that by pre-generating the files once, you save
the cost of having to generate the response every time with a dynamic
technology like JSP. If the pages are static, there is no point to
building them over and over again...

I have posted my essay on the advantages and disadvantages of HTML
static macros. I came up with 11 advantages and 4 disadvantages.

see http://mindprod.com/jgloss/htmlstaticmacros.html

I also describe the tools I wrote to implement them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top