使用CSS / Javascripting包含的PHP站点结构技术

Technique #1:

  • Single index.php file which includes header.php, navigation.php, footer.php and content files depending on URL variable.

Problems #1:

  • You can't add individual .CSS files specific to your content pages because they have to be added in the main index.php file and may conflict with other content pages.
  • If you have javascript's needed for specific content pages you MUST load all potentially used JS files in the index.php file. This means you unnecessarily load JS files for content pages where they aren't needed.

Technique #2:

  • template.php file for each major page of website which includes header.php, navigation.php, footer.php. Content is not included via a file but rather the template file is used as the content file.

Problems #2:

  • Any changes made to the the template has to be duplicated to every other major page manually.

I started using technique #1 until I ran into major javascript issues. I am now considering moving to technique #2 and just dealing with template changes as necessary.

What technique do you use and how do you solve the CSS/JS include issue?

I tend to have one CSS for the whole web site or at most 2 CSS file when a unique CSS file will be very long. In such case, I define in the first CSS file the general ayout of the web site and the common structure shared by the web site pages, and in the second CSS file I will define the layout specific to a page or to an object.