Jump to content

Using one javascript tag to "reload" game attributes at once (just read if conf)


slyte33

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.