0

I've read this: PHP & CSS - Should I Link or Include?
and this: What is the best practice to include header and footer in PHP?
and also this: Creating a PHP header/footer

Nice pieces of information there, but my question is different. I am including header and footer no problem. Sometimes I face this issue:

Different pages with different data and different scripts required, specifically Ajax. I separate my Ajax post requests with different files to include it only on its page. Of course if I have all the <link> and <script> in header.php and footer.php they will be included everywhere, so thats useless code being rendered.

Someone in Stackoverflow once told me that it's not a good practice to write an if condition to run scripts based on a page.

So what is the best practices for this?

P.S.
Kindly don't be harsh on me if this question might be so simple, being a self taught developer makes me miss lots of "might be basic" things since I don't have a person to guide me. Appreciate it.

Abdulrahman Mushref
  • 1,012
  • 2
  • 18
  • 40
  • Have you messed around with the locations of the css? ie. ``, ``, ``, etc – x43 Dec 02 '21 at 15:28
  • 1
    My team uses `/assets` or `/resources` and all links always uses items in there. – Forbs Dec 02 '21 at 15:30
  • As for your second question, that's for you and your template system to work out. Get some inspiration from Twig's named blocks for example: https://twig.symfony.com/doc/3.x/templates.html#template-inheritance – deceze Dec 02 '21 at 15:39

0 Answers0