How to autorefresh a TXT file on website

prsn
prsn used Ask the Experts™
on
Hello experts

We have a .txt file on our webserver that is refreshed every 20 sec for aprox 3 or 4 hours. After that the file is no longer updated. When the user clicks on the link it will open that .txt file however to get the latest update the user will need to refresh the browser. Around 90% of our users will be using cell phones or tablets.

Is there a PHP / Jquery/ javascript or any easy solution to get this done?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
Yes.  You might consider using a timer to refresh the client's data from the server-side data source.  JavaScript setInterval() function can be helpful.  This article shows the general design.
http://www.experts-exchange.com/articles/14519/A-jQuery-Progress-Bar.html
Most Valuable Expert 2011
Top Expert 2016

Commented:
Having said that, please be aware that data coming from the server to a mobile device has a battery cost that is about 10x the same data coming from storage in the mobile device.  Sorry, I have no citation for this, but I believe it to be true.  So for the sake of your users you might consider telling them the last time the data was updated, or whether it is still being updated.  You might give them the option to turn on automatic polling or to work manually, and just use what they got most recently.
greetings prsn, , you ask about needing to "refresh the browser" to get the latest TEXT file update, by doing what you call "clicks on the link" . . I am not sure about what may be a reason for this, OR what could be done to fix it, since the cause of it, is not clear to me? ? ?
If you could tell us more about what is on the web page that is suppose to load the text file, is it just a link <a>  like -
    <a href="info.txt">See the Information</a>

or does "the click"  involve some jquery javascript ?

I think that if you overwrite a file with PHP as you say "refreshed every 20 sec", then the time stamp for that file is also changed, which may or may not be useful for this?
But it's difficult 4 me 2 say what might be the problem, the browser catch maybe?
Top Expert 2015
Commented:
I love intercooler.js for ease of install and use. See a polling example here. It's AJAX all via HTML attributes.

<div ic-prepend-from="/poll" ic-poll="1s" ic-target="#content">
    <div ic-target="this">
      <div class="btn btn-default active" ic-post-to="/play"><i class="fa fa-play"></i></div>
      <div class="btn btn-default" ic-post-to="/pause"><i class="fa fa-pause"></i></div>
    </div>
    <div id="content" ic-limit-children="5">
    </div>
  </div>

Open in new window


http://intercoolerjs.org/
... had it working in 5 minutes in production on multiple projects

is all you'd do frontend, then read the TXT file with a pointer in the PHP.

Author

Commented:
Hello Everyone

Thanks for the reply and recommendations. I will try your options to see which one one suit our needs.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial