slyte33 Posted September 7, 2010 Share Posted September 7, 2010 Okay, the title may sound a little confusing but it's the best way I could explain it. I think it's better to understand what I'm doing by looking at my function below: <? function refresh($name,$num,$time) {?> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> update<?=$num?>(); function update<?=$num?>() { num = Math.random(); $('span.<?=$name?>').load('refresh.php?a=<?=$name?>'); setTimeout('update<?=$num?>()', <?=$time?>/1000); } </script> }<? //refresh('name of span tag','JS update#', 'refresh time'); refresh('spantag1','1', '5'); refresh('spantag2,'2', '5'); refresh('spantag3','3', '5'); ?> As you can see this would output 3 javascript codes on the page. I'd then use the span tag to allow this to refresh every 5 seconds like below: <span class=spantag1>This contains the contents that will refresh in span tag one</span> to refresh every 5 seconds. This is a huge problem because I have about 50 tags that need to be refreshed every 'x' seconds. Because of using all these 50 refreshes my page size is 1.36MB large Without all this javascript my page size is only 38KB. I'm wanting to use one javascript code but allow up to 50+ raw data that is inside the span tag to be refreshed. <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> update<?=$num?>(); function update<?=$num?>() { num = Math.random(); $('span.<?=$name?>').load('refresh.php?a=<?=json_encode($arr)?><?=$name?>'); setTimeout('update<?=$num?>()', <?=$time?>); } </script> Sorry if it didn't make sense, tried my best lol. Thanks and all help is much appreciated. Quote Link to comment Share on other sites More sharing options...
Hypnos Posted September 7, 2010 Share Posted September 7, 2010 Because of using all these 50 refreshes my page size is 1.36MB large Without all this javascript my page size is only 38KB. I don't see how this could be 1.3MB? That javascript is about 0.5KB. Even 50 of them won't be a 1MB. Are you sure your code isn't creating too many of them. You could cut down on your javascript if you combined the datasets into fewer requests with XML or JSON. Quote Link to comment Share on other sites More sharing options...
slyte33 Posted September 7, 2010 Author Share Posted September 7, 2010 Because of using all these 50 refreshes my page size is 1.36MB large Without all this javascript my page size is only 38KB. I don't see how this could be 1.3MB? That javascript is about 0.5KB. Even 50 of them won't be a 1MB. Are you sure your code isn't creating too many of them. You could cut down on your javascript if you combined the datasets into fewer requests with XML or JSON. Yes I am sure. If i use the function once [ refresh('spantag1','1', '5'); ] for example and view the source, it will display it only once. When I remove the function, my webpage loads within half a second. When using it, it takes 3-4 seconds to load everything. Quote Link to comment Share on other sites More sharing options...
slyte33 Posted September 9, 2010 Author Share Posted September 9, 2010 I figured it out. Inside the function I included: <script type="text/javascript" src="js/jquery.js"></script> So basically every function that was echoe'd was loading the entire jQuery file! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.