Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Inserting different javascript to each page when using header include

    I'm a newbie to PHP and programming.

    Some javascripts need to be inserted in html head tag, but I'm currently inserting head part using require. e.g.
    require ('header.php');

    I saw the other day that inserting different title to different page using a simple PHP fuction.

    Code:
    function header ($title) {
    ...
    <title> $title </title>
    ...
    header (First page);
    etc etc.

    I think there must be a way like above to insert different javascripts to each page, because it's not efficient to insert the javascript which is not used on every page.

    How do you smart guys insert some javascript on specific page using php functions?

    Can anybody help me, please? Thanks in advance.

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    You could let your header.php decide which javascript to include depending on which page was requested ($_SERVER["REQUEST_URI"]).

    But it may be better if you put everything you may need into one javascript which you put into all the sites, because after the first time it's loaded it's stored in the browser cache anyway. Putting different javascripts into different pages means more HTTP requests and may slow down your site.
    Last edited by venegal; 05-03-2009 at 12:23 AM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •