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.