which is best way to keep page updated in real time ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

which is best way to keep page updated in real time ?

lately i kinda thinking about this. let's say i have a simple web that updated frequently. no session or anything fancy, just blog-like website. i normally make a client to automaticly send a request continously to update the page. but it got me thinking. isnt this will burden the server at some point ? the i get an idea, how about make the client that listen to the server, this way the server will only need to send a broadcast once its needed. but i kinda concern about the security here, and i'm not even sure if its possible. if you have different perspective or solution, i'll be glad to hear them out :)

2nd May 2019, 9:26 AM
Taste
Taste - avatar
11 Answers
+ 6
WebSocket can do the job. https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications Client needs open the connection, create onmessage to listen server data.
2nd May 2019, 12:04 PM
Calviղ
Calviղ - avatar
+ 4
WebSocket server setup here using Nodejs https://flaviocopes.com/node-websockets/
2nd May 2019, 12:17 PM
Calviղ
Calviղ - avatar
+ 3
Ajax
2nd May 2019, 3:53 PM
Radu Baloi
Radu Baloi - avatar
+ 2
Interesting ~
2nd May 2019, 3:23 PM
Gordon
Gordon - avatar
+ 1
Interesting and practical For the "broadcast", can the server be submitting to connected client only? And it also set an interval to test whether the client is still connected.
2nd May 2019, 10:25 AM
Gordon
Gordon - avatar
+ 1
thats the main problem, unlike webhook we cant test or send anything directly to client without any request. so its hard to decide which client still connected to the server
2nd May 2019, 11:11 AM
Taste
Taste - avatar
+ 1
Hm....i remember Martin has done something similar. Martin
2nd May 2019, 11:43 AM
Gordon
Gordon - avatar
0
Calviղ I think this is what firebase is doing, isn't it?
2nd May 2019, 12:32 PM
Gordon
Gordon - avatar
0
Firebase can provide WebSocket too, but we normally use it as database storage which provide real time access.
2nd May 2019, 3:07 PM
Calviղ
Calviղ - avatar
0
I will say websockets as they have less overhead and faster communication and can be preferred over http connections. More you can research how to implement when you are developing based on the scripting language that you use for frontend - Angular, React or any other.
3rd May 2019, 2:42 AM
Mal Pat
Mal Pat - avatar
0
Please tell me how to work Sql with php in phone
14th May 2019, 1:31 PM
Janasena PSPk
Janasena PSPk - avatar