AJAX vs HTML5 in terms of resource usage

Status
Not open for further replies.

jportfol

New Member
Messages
6
Reaction score
0
Points
0
Hey, I'm trying to update my page when a user makes a new post, and using AJAX, it works. But with AJAX I found that I was soon locked out for an hour probably because the AJAX is reaching out to the PHP page to pull the last entry of the file/database every 2 - 4 seconds. In the free hosting, I'm pretty sure that's too resource intensive. Maybe not in the paid, but not sure. Anyway. I temporarily fixed that by only activating once per refresh...kind of defeats the purpose.


I was wondering, if I used HTML5 Server Side Events to accomplish the same goal, would that still be as resource intensive?

Other question, in the paid version, does that limit go away?

Thanks!

...I guess real-time updates aren't THAT important. But I'd like for people not to refresh every time...
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
If you mean WebSockets, it'll be worse since there'll be persistent connections to maintain along with the associated memory to keep them alive. You do get push, but it doesn't come free--it works best if your updates are large relative to the cost of keeping the socket open or if the nearest thing you can get to real-time over TCP/IP (not very) is critical.

Unless you're running an auction or similar scenario, there's no reason I can think of for a 2-4 second update schedule. If you actually do need that sort of schedule, you may be able to trim quite a bit by making a HEAD request and only switching to GET if there's an update to be had. If your database writes are far less frequent than your reads, you can do a cache on write. Combined with the HEAD, you should be able to turn the request around with very little processing. For something like a forum, you wouldn't notice any appreciable increase in latency if you bumped the time up to 20-30 seconds -- only the user who submitted would notice that his own posting is slow to update, and you can do that locally when the 200 for the submission is returned.
 
Status
Not open for further replies.
Top