开发者

JS refresh minimu amount

What is the minimum refresh time for a js refresh? What potential problems do I face with super small refreshes like every 40 millis开发者_JS百科econs... I have a good reason to do so its not madness.

    function refresh(){
    var refreshTime = 40;
    setTimeout("location.reload(true);",refreshTime);
    }


For a single timeout, it doesn't matter.

Instead of passing a string as a first argument, I recommend to pass a function, which allows more flexibility:

setTimeout(function(){
    //Do anything you want
}, refreshTime);

For intervals (window.setInterval()), I usually take 50 as a minimum, because most tasks do not have to be executed over 20 times a second. Heavy functions in an INTERVAL can cause the browser to freeze (eg: multiple CSS updates -> re-rendering the page).


This code will be probably OK.

It doesn't matter which time you insert there, I sometimes use 1


There's nothing wrong with the code, per se (except the string passed to setTimeout rather than a function). However, refreshing a page every 40ms is not going to give the most pleasant user experience. Page elements will flicker, clicks may sound through the speakers.

It sounds to me like you need to go for something like Comet to keep your page updated. This should be less stressful for the server, and smoother overall.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜