Frage

What is the minimum refresh time for a js refresh? What potential problems do I face with super small refreshes like every 40 millisecons... I have a good reason to do so its not madness.

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

Lösung

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).

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top