Jump to content

[SOLVED] Speed up Javascript sources <SCRIPT></SCRIPT>


carefree

Recommended Posts

Ok heres one I could replace - a simple onclick popup window can this be converted to php??

 

 <!-- 
function Start(page)
{
OpenWin = this.open(page, "CtrlWindow","toolbar=No,menubar=No,location=No,scrollbars=No,resizable=No,status=No,width=200,height=200,left=150,top=150,");
}
//-->

I have about 8 javascipt src files included in my template and its slowing its down the whole site heaps. Is there a way I can speed it up???

 

Yes. You can atleast join them into one script.

<?php // joinscript.php

// optionally disable cache
Header("Pragma: no-cache");
Header("Cache-Control: no-cache"); 
Header("Expires: ".GMDate("D, d M Y H:i:s")." GMT");

function GetCont($file) {
 if (file_exists($file)) {
   $arr = explode("\r\n", file_get_contents($file));
   $retarr = array();
   reset($arr);
   while(list(,$l) = each($arr)) {
     $l = trim($l);
     if (!empty($l))
       $retarr[] = $l;
   }  
   return "\n".implode("\n", $retarr)."\n";
 }
}

echo GetCont('./first_script.js');
echo GetCont('./second_script.js');
     
?>

 

To call such joining use

<script type="text/javascript" language="JavaScript1.2" src="joinscript.php"></script>

Man you just don't get my point... You can't use PHP to pop up windows, show alert messages, and use other events like in javascript. PHP's output is just plain html / javascript (or whatever) sent to the user.

PHP and javascript just do different things.

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.