rain13 Posted August 21, 2013 Share Posted August 21, 2013 (edited) Hello.I use window.setInterval to constantly call function that updates info from server using XMLHttpRequest. The strange problem with that is that it causes textarea to miss some characters as you type. however if I replace code that gets new info from server with code that just returns 0, then it works nicely.What's more interesting is that only firefox seems to have this problem.Here you can try to type something (use firefox): <link removed to minimize traffic from searchengines> Edited August 21, 2013 by SoItBegins Link to comment Share on other sites More sharing options...
justsomeguy Posted August 21, 2013 Share Posted August 21, 2013 You are clobbering the browser. That is way, way too often to be sending out requests for updates. Link to comment Share on other sites More sharing options...
thescientist Posted August 21, 2013 Share Posted August 21, 2013 (edited) I noticed that you have set the async param to false. That means the page is constantly being blocked each time the interval callback function runs to make the AJAX request. Combined with how often you are sending requests, its bound to create a bottleneck. Edited August 21, 2013 by thescientist 1 Link to comment Share on other sites More sharing options...
rain13 Posted August 21, 2013 Author Share Posted August 21, 2013 Yeah, I decreased that time to 500 to make that effect greater. It was normally 3000, but that didn't cause noticeable txet loss so I decreased that time for this demo only. the interesting thing is that other than firefox doesn't seem to have problem with that. Link to comment Share on other sites More sharing options...
davej Posted August 21, 2013 Share Posted August 21, 2013 (edited) Why would you want to update text based on a timer? Wouldn't the keyup, onchange or onblur events make more sense? Edited August 21, 2013 by davej Link to comment Share on other sites More sharing options...
rain13 Posted August 22, 2013 Author Share Posted August 22, 2013 Because it's general code that gets unread PM count. It's actually in main.html file into which text editor is read. I wrote html parser that allows you to replace placeholders with other file so I have main file that defines general look of page and then I load text editor into it from it's own file so I wont have to store same code in every file. Checking constantly would make that unread count change even when you do nothing. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 22, 2013 Share Posted August 22, 2013 The synchronous requests are probably the issue. Once you get it working as you want, I would recommend setting that timeout to 10 seconds or more. It's always better to put less load on the browser and the server, especially if you're expecting high traffic. For something like that notification, someone wouldn't know the difference if it told them they had a new message after 10 seconds (worst case) versus 2 or 3 seconds. You could probably even set it to a minute and people still wouldn't notice. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now