|FAQ : Frequently Asked Questions|
Is there any way to dynamically merge other html scripts
into a given html?
What, at least in my opinion, would be needed is some include function to be interpreted / executed from the client browser at page load time. Unluckily, nothing like this -- as far as I know -- is available. This means that any include function must be carried over from the server site.
There are two ways you can obtain this dynamic merging:
The SRC attribute of the <SCRIPT>
tag lets you specify a file
HTML). For example:
This attribute is especially useful for sharing functions among many different pages.
The closing </SCRIPT> tag is required.
The SRC attribute can specify any URL, relative or absolute. For example:
which the server sends back in the HTTP header.
HTTP Server-Side Includes (SSI) provide these type of functionalities (for extended information on SSI, please check Using Server-Side Includes in HTTP Server for AS/400 Web Programming Guide).
Server-side includes allow you to insert information into dynamically created (via CGI) and static HTML documents before the server sends them to the client.
Note 1- The way the HTTP server performs the SSI is to scan the document before sending it to the client. This task is extremely expensive in terms of CPU load. It is therefore recommended to limit the use of SSI to the cases really needed, in order to avoid substantial HTTP serving performance degradation. For instance, requesting SSI intervention on all static pages would cause perceivable response time degradation.
We are now going to describe the steps to implement include support for CGI created HTML pages.
Imbeds CGI SSIOnly
The Imbeds HTTP directive instructs the HTTP server about the SSI services to be performed. See HTTP Server for AS/400 Webmaster's Guide Section 22.214.171.124.
The HTTP server, instructed to run SSI for CGI pages with content type text/x-ssi-html, will just scan the documents if produced from a CGI and if content type = text/x-ssi-html. Therefore the SSI-processing extra load would be kept to the very minimum requested by such documents.
Only when receiving a CGI-originated text/x-ssi-html document, the HTTP server would scan it looking for imbedded SSI directives.
<!--#include virtual="/path/file" -->
are the path and the file name to be included, before being interpreted from the HTTP server configuration mapping directives.
Note 2. In your CGI external html include similar SSI directives in any point you want another piece of html be included. You can have more than one such SSI directive in a given external html.
Note 3. It must be clear that --as the inclusion(s) is (are) done by the HTTP server after receiving the html buffer from the CGI-- the html pieces to be included are not visible to the CGI, in other words "the html pieces to be included" are static.
Should you need to include dynamic pieces (that is, pieces to be processed from a CGI), then you should better refer use our gethtmlifs subprocedure.