-1

I am not very well versed with internal HTML and PHP stuffs so I was wondering if I break my code into multiple php files and then include them in 1 html file will that add to the number of HTTP requests? Or it will be just 1 request since the browser is actually rendering the html file.

The code that I have is:

<?php include 'header.php'; ?>
<body></body>
<?php include 'footer.php'; ?>

So now will this index.html send 3 requests[1 for homepage + 2 for internal pages called by php] or just 1?

I am doing this keeping in mind: 1. Reducing HTTP requests 2. Reduce code size to improve site speed

Swayam
  • 25
  • 7
  • This will result in only 1 request but you probably need to rename your file to `index.php` as a file with the `.html` extension normally does not process the php. – jeroen Mar 04 '15 at 08:05
  • Are you including php in html files? – Amit Verma Mar 04 '15 at 08:06
  • If so, make sure you have instructed your web server to treat .html as .php – Amit Verma Mar 04 '15 at 08:08
  • @AmitThakur umm I guess no! Cause I was having the idea that my index.html will call specific html coding from php files respectively. So now I guess that won't be possible.. I need to change the index.html to index.php but then how will I add the rest of the html in the index.php?? – Swayam Mar 04 '15 at 08:14
  • You can include your html in your php page .but the extension must be .php – Amit Verma Mar 04 '15 at 08:17
  • Tizag wrote a very helpful tutorial on [Php include](http://www.tizag.com/phpT/include.php) I hope this helps. – Amit Verma Mar 04 '15 at 08:23

1 Answers1

1

It will be only one request because the PHP(Server side language) include action will be performed on server side and browser will only get final result in one HTTP request.

Also your code will not work if it is 'index.html' file make it 'index.php' so code can be executed other wise it will be rendered as plain static html page.

Sachin Joshi
  • 119
  • 5
  • In that case how will I write the rest of the html inside my index.php? Can you show me some samples coding? – Swayam Mar 04 '15 at 08:15
  • Renaming index.html to index.php will not affect your any current html content. whatever you write inside tags will be treated as php code otherwise will render as normal html content. Your current code will work fine just rename index.html to index.php – Sachin Joshi Mar 04 '15 at 08:17