Basic Ajax Cache Issue

前端 未结 3 1034
感情败类
感情败类 2020-12-07 06:48

I have a single page that I need to on occasion asynchronously check the server to see if the status of the page is current (basically, Live or Offline). You will see I have

3条回答
  •  [愿得一人]
    2020-12-07 07:13

    I think Nick Craver has the right response.

    For the other point of the question which is you SetTimeout , you could use SetInterval() and avoid the recursive call. But in fact I would stay with a setTimeout() and add a factor on the 15000 time. set that factor as a parameter of checklive. Then you will have a check which will be delayed progressively in time. This will avoid a LOT of HTTp requests from the guy which his still on your page since 48 hours.

    Chances are that most of the time users will check for new pages in a regular manner, but someone staying for a very long time on a page is maybe not really there. Here's a piece of code I had doing that stuff.

    function checkLive(settings) {
        (...) //HERE ajax STUFF
        setTimeout(function() {
            if ( (settings.reload <2000000000) && (settings.growingfactor > 1) ) {
                checkLive(settings);
                settings = jQuery.extend(settings,{reload:parseInt(settings.reload*settings.growingfactor,10)});
            }
        },settings.reload);
    }
    

提交回复
热议问题