Including HTML or PHP files to make Code less redundant

+1 Jonas Meise · June 6, 2015
Hey Guys

While programming my website I noticed it is messy if I place my whole navigationbar html code in every php file. So in the internet I came across the suggestion that I could make a separate navbar.php file and whereever I had it before in my other files I can replace that with :

<?php include_once 'navbar.php'; ?>

It works fine and looks a lot less messy now but I wonder if this can slow down the website when I do that with too many things since it has to load multiple php files whenever I load a page.

Can any of you tell if this can slow down the website and if yes, is it a noticeable difference in speed? 

Thanks for your advice :)

LuPaw

Post a Reply

Replies

Oldest  Newest  Rating
0 Jonas Meise · June 6, 2015
Okay thanks for the info :) Guess I'll do it that way then.
0 Ian Arbuckle · June 7, 2015
It won't affect loading time at all. However to decrease loading time, ensure that your <script> tags are placed at the bottom of your html file as this will reduce the loading time by a tiny fraction which makes a big different. If you place it inside the <head> tag, it will load the JS files first which cause the web page to load slower.
0 Ian Arbuckle · June 7, 2015
makes a big difference *
0 Jonas Meise · June 7, 2015
Okay that makes sense. But what if you have a Javascrip action that has to run as soon as the site loads. Then you would have to put the scrip tags at the top right?
+1 Kaveh Greenwood · June 9, 2015
This won't decrease load times but may slightly increase load times. The include files are being loaded on every page, the temp int files already have those include files stored therefore leaving them easier to load on the next new page. The only new information that must load is the unique content to that page.
  • 1

HTML / CSS / Web Design

103,682 followers
About

Discuss, share, ask, learn and teach HTML5 and CSS3.

Links
Moderators