Avatar of Kinderly Wade
Kinderly Wade
Flag for United States of America asked on

Designing Web Structure

Dear experts,

After I reviewed some basic website structure design, I came up with these two solutions just not sure which one to go by or there are other better methods out there.

Solution 1:
1. create these sections:
     i. header
    ii. body
    iii. footer

2. using php function include to add those components to the page:
    for example if I want to create  home, about, contact, etc.... pages
   I can do this:

    home.php
 ----------------------------------------------
    <!DOCTYPE html>
    <html>
      <head>
      </head>
     <body>
             <?php include "path/header.php";?>
             ...........
           <?php include "path/footer.php";?>
    </body>
   </html>

I can have a navigation bar in header.php and using <a> tag to navigate to each page. The downside is that for each of the page that I created, I have to make sure all pages include header.php and footer.php. The upside is that I don't need to deal with javascript or any additional code. I believe the page upload will be fast as just in plain CSS and html code with minor php code (I am excluding any other default js libraries such as bootstrap.js, respond.js, etc..... which just simply talking about my code only).

Solution 2:

I can simply create a single page look similar to the structure from solution 1 and using the home.php as example:

    home.php
 ----------------------------------------------
    <!DOCTYPE html>
    <html>
      <head>
            <script type="text/javascript" src="path/JQuery.js"></script>
      </head>
     <body>
             <div id="header_content"></div>
            <div id="body_content"></div>
           <div id="footer_content"></div>
    </body>
   </html>

I only need to create a template page for including header, footer and body content like this:
    i. header.php,
    ii. footer.php,
  iii. body.php (this body can be any content that I want to put into the body_content div by naming the file to home.php, about.php, etc.....)

I will be utilizing the JQuery AJAX to load up the page into each of the div section like this:

    1. header.php into the header_content div
    2. footer.php into the footer_content div
    3. xxx.php into the body_content div

Upside is the that I just need to maintain a single section by page as in I don't need to include header.php or footer.php to all my pages. The only thing that change is the content in the body_content div.

Downside is that there will be more code running to render the page.

I am not sure which method will be the best and used by most web designers. I wish to get an idea of what it can be done and if there are other methods out there. Thanks.
Web DevelopmentHTMLJavaScript

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Jason Carson

If you have a lot of pages I would go with solution #1. If at some point in the future you need to edit the header code it's easier just to edit header.php once and it would be included in all your pages.

If on the other hand you went with solution #2 and you needed to edit something in the header you would have to edit all your pages  <div id="header_content"></div> code one at a time. A time consuming process.
Kinderly Wade

ASKER
Hi Carson,

I thought the solution #1 requires more work which I have to type in php code "include" for all my pages instead of the solution #2.

The only thing that will change in solution #2 is the content within the body_content div tag
SOLUTION
Jason Carson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Kinderly Wade

ASKER
Thanks Dave!

I have another question upon solution #2. When will be the time to use it instead of solution#1?
Thanks.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Dave Baldwin

The only reason to use #2 is when you want to change something after the page has loaded.  Or maybe hide things from the search engines?  I have done 1 or 2 pages using solution #2 and they had the problems I mentioned.  Or a customer has an existing site where you have to add things to it.

I do most sites with method #1 where the 'include' for navigation only changes when I have a new page to add to the site.