Forum Moderators: coopster
A Javascript can access any content that it has pre-loaded, or loaded to the browser for the current browsing session. Once the browser is finished loading, that's it. No more talking to the server.
Even though you might have some dynamic things going on via JavaScript, there is no real interaction with the server once the page is done loading. All the information that the JavaScript is using is already loaded to the browser. JavaScript cannot talk to the server interactively and wait for a file size update. The only thing that this will return will be the original filesize when the page was loaded.
Hope this helps :)
filesize()is in your php script, checking the size of the text file on your own server, this will work. You might also want to use:
header(Cache-control: nocache);
and maybe some other cache headers suggested here [be.php.net] to make sure browsers don't cache the content; normally they won't cache PHP output since it doesn't have relevant cache headers, but some browsers might just figure that nothing could have possibly changed after only 3 seconds - I know I've encountered this with images.
If this functionality is really important to you, you might still want to look into getting a java applet like jpilot. PHP has a pretty lousy reputation when it comes to chat apps since it's stateless, though this will probably be changing somewhat with 'streams' etc - but then you really have to know what you're doing. An applet will give your users a 'smoother' chat experience and might also help you save bandwidth. If you really, really want to do this with PHP and javascript, you can check out the article Crouching Javascript, Hidden PHP [sitepoint.com].