0

If I use PHP's include function to import parts of the page that are repeated like navigation, header and footer for example - will that make the code more or less efficient or would it be the same? Thanks

StuntHacks
  • 457
  • 3
  • 15
  • 1
    Does [this](https://stackoverflow.com/questions/2106700/efficiency-for-including-files-of-functions-in-php) give you an answer? – PeterMader Jun 07 '17 at 14:12
  • perhaps try to append simple example of one and the other case – rudolf_franek Jun 07 '17 at 14:12
  • 1
    You're worrying about a micro-optimization. Your time would be better spent deciding if you should move the client side html to javascript. – Matt Jun 07 '17 at 14:13

2 Answers2

0

The include()-function reads the entire content of the file you are including, then execute it and then paste the result right where it is called. So regarding code speed, it would be less efficient. However, if you don't include extremely large files then it shouldn't make much of a difference.

StuntHacks
  • 457
  • 3
  • 15
0

I would agree that this is probably not something that you should concentrate on too much. Most of the time you can use includes freely without worrying about how fast it is. Ultimately, includes like this are for saving your time as a programmer.

Another factor to think about on the very low level is that the file you are accessing might be at a different place on the disk. So, that means that it may not be cached, and it will take longer to go to the file location than if it were located within the file itself.

avgeek96
  • 116
  • 7