php IF statement to load/not load Javascripts - Is this smart?
<p>I am not sure if this general question is even allowed in here but I try it anyways. I am creating a new site (just for fun and to "train" my skills). I am at a point where I have some lines of javascript code, but the code is not needed on every page.<br></p>

<p>So I have decided to paste ALL javascripts into a php file (javascript.php) and inside that file I have added following lines:<br><br></p>

<pre><code>&lt;?php  $site_name = basename($_SERVER['REQUEST_URI'], ".php"); ?&gt;
&lt;?php if ($site_name == "index") { ?&gt;
&lt;script type="text/javascript"&gt;
//script 1
&lt;/script&gt; 
&lt;?php } elseif ($site_name == "index1") { ?&gt;
&lt;script type="text/javascript"&gt;
//script 1
&lt;/script&gt; 
&lt;?php } elseif ($site_name == "index2") { ?&gt;
&lt;script type="text/javascript"&gt;
//script 2
&lt;/script&gt; 
&lt;?php } elseif ($site_name == "index3") { ?&gt;
&lt;script type="text/javascript"&gt;
//script 3
&lt;/script&gt; 
&lt;?php } ?&gt;
</code></pre>

<p><br>
It works fine.<br>But, as I am a coding newbie, I was wondering if this a smart solution? Could you girls and guys tell me your opionion and why it is smart/dumb to do this?<br>Thanks!</p>
