[thelist] HTML optimization advice, please

Ray Hill ray at opengrid.com
Thu Sep 20 13:49:55 CDT 2001


> TASK:
> Optimize (for maintenance) the "Header" and "Footer" sections,
> through SSI or other.

APPROACH #3:
Use PHP to print the header/footer content.  Since you can make the printing
of said content into a function, it would eliminate the need for 40
different files, and could instead be just a switch statement within the
function that prints different content depending on which sectionid you pass
it.

You can configure your server to parse your existing .html files as PHP, so
you shouldn't have to change your file names.  And since PHP works on both
IIS and Apache, porting it over to a different machine type in the future
would not be a problem (and might actually be a benefit, since PHP runs
faster as an Apache module).

Something like this:


SAMPLE_PAGE.HTML
<?
include "template.php";
template_printHeader("ThisSectionID");
?>

<!-- Content goes here -->

<?
template_printFooter("ThisSectionID");
?>



TEMPLATE.PHP
<?
function template_printHeader($mySectionID) {
  ?>
  <html>
  <head>
    <?
    switch ($mySectionID) {
      case "SectionOne":
        // Print content for this section here.
        break;
      case "SectionTwo":
        // Print content for this section here.
        break;
      default:
        // Print default section content here.
        break;
    }
    ?>
  </head>
  
  <body bgcolor="#FFFFFF">
  
  <!-- Formatting/navigation table goes here -->
  <table border="" cellpadding="" cellspacing="">
    <tr>
      <td>
  <?
}

function template_printFooter($mySectionID) {
  ?>
      </td>
    </tr>
  </table>
  
  </body>
  </html>
  <?
}
?>



This also allows you to set other variables in the switch statement that can
be referred to further down in the individual documents' content.  And, of
course, you can distill the navigation dropdowns into their own file and/or
function  and include them into the template file, to make it easier to
manage.


--ray





More information about the thelist mailing list