开发者

Does Javascript SetTimeOut Affect Page Performance?

I am writing an AJAX script that basically calls a PHP page and requests some information. The PHP page queries a database. I want to set the page to make the call every 5 minutes, but the only way I know how to do so is by using the settimeout function. I am wondering if this settimeout function is constantly running is this going to be harsh on 开发者_Go百科the page's performance? is there another way to go about this?


I don't really thing the problem is setTimeout, perhaps it is the way you have built the script.

In fact, most of the time setTimeout it's preferred, for a reason, setTimeout will wait the execution of your script, setInterval will execute in every interval without waiting.

Pls look here at the bottom:

https://developer.mozilla.org/En/Window.setInterval

If there is a possibility that your logic could take longer to execute than the interval time, it is recommended that you recursively call a named function using window.setTimeout.


use setInterval. They should render the same results (~0 performance loss), but setInterval is the obvious way to go.

Think about Google Wave: they send an AJAX request for every letter you type, yet it doesn't feel slow at all, so one request every 5 minutes is nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜