December 22, 201114 yr Just wondering if anyone can offer any advice here. On my website I have quite a few js scripts, all for different things. I didn't want them loading on pages where they weren't needed, so came up with the code below, to load the scripts only on the pages they are needed. Is there any real benefit from doing this, and is the increased use of php in the page header include anything to worry about? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title><?php echo $page_title; ?> | Operation: Sore Feet</title> <meta name="description" content="<?php echo $pgDesc ?>"></meta> <meta name="keywords" content="<?php echo $keyWords ?>"></meta> <meta name="author" content="Stuart Boardman"></meta> <meta name="copyright" content="© Stuart Boardman, 2011"></meta> <link href="http://opsorefeet.info/css/stylesheet.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" type="image/x-icon" href="http://opsorefeet.info/favicon.ico"/> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <!-- SHADOWBOX JS --> <?php $shadowpages = array('index.php', 'about.php'); foreach ($shadowpages as $page) { if (strpos($_SERVER['PHP_SELF'], $page)) echo '<script type="text/javascript" src="http://opsorefeet.info/js/shadowbox.js"></script> <script type="text/javascript">Shadowbox.init({ language: \'en\',overlayOpacity:0.8,overlayColor:\'#ccc\', players: [\'img\', \'html\', \'iframe\', \'qt\', \'wmp\', \'swf\', \'flv\'] }); </script>';}?> <!-- FORM VALIDATION JS--> <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo '<script type="text/javascript" src="http://opsorefeet.info/js/jquery.validate.min.js"></script> <script type="text/javascript">$().ready(function() { $("#contactform").validate(); });</script>';?> <!-- DATATABLES JS --> <?php $tablepages = array('traininglog.php', 'sponsors.php'); foreach ($tablepages as $page) { if (strpos($_SERVER['PHP_SELF'], $page)) echo '<script type="text/javascript" src="http://opsorefeet.info/js/jquery.dataTables.min.js"></script> <script type="text/javascript"> /* <![CDATA[ */ jQuery.fn.dataTableExt.oSort[\'uk_date-asc\'] = function(a, {var ukDatea = a.split(\'/\');var ukDateb = b.split(\'/\');var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;return ((x < y) ? -1 : ((x > y) ? 1 : 0));}; jQuery.fn.dataTableExt.oSort[\'uk_date-desc\'] = function(a, {var ukDatea = a.split(\'/\');var ukDateb = b.split(\'/\');var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;return ((x < y) ? 1 : ((x > y) ? -1 : 0));}; $(document).ready(function() {$(\'#log\').dataTable( {"sPaginationType": "full_numbers","aoColumnDefs": [{"sType": "uk_date", "aTargets": [0] },{ "bSortable": false, "aTargets": [ 3 ] }]} );} );/* ]]> */ </script>';}?> <!-- DATEPICKER JS --> <?php $aboutPages = array('sponsoredit.php', 'logedit.php','addlogentry.php','sponsoradd.php'); foreach ($aboutPages as $page) { if (strpos($_SERVER['PHP_SELF'], $page)) echo '<script type="text/javascript" src="http://opsorefeet.info/js/jquery.datePicker.js"></script> <script type="text/javascript" src="http://opsorefeet.info/js/date.js"></script> <script type="text/javascript">Date.format = \'yyyy/mm/dd\';$(function() {$(\'.date-pick\').datePicker();});</script>';}?> </head> <body> <div id="wrapper"> <div id="main" class="clearfix"> Cheers, Stu Edited December 22, 201114 yr by StuartPB
Create an account or sign in to comment