FAQ : Frequently Asked Questions | ||
|
21. |
Q:
Is there any way to dynamically merge other html scripts
into a given html?
A: In a sense you are requesting something like a /copy pre-compiler function. This could be extremely useful when you have many html pages sharing some pieces of html/javascript. A /copy-like function would allow to keep these common pieces external, and to include them wherever needed, thus reducing both html scripts development time and maintenance. 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:
Imbedding external JavaScript code The SRC attribute of the <SCRIPT>
tag lets you specify a file
as the JavaScript source (rather than embedding the JavaScript in the
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: External JavaScript files cannot contain any HTML tags: they must contain only JavaScript statements and function definitions. External JavaScript files should have the file name suffix .js,
and the server must map the .js suffix to the MIME type application/x-javascript,
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 1.1.3.4. |