wturrell's avatar

Livewire general advice - ajax vs web sockets

I'm very much at beginner level with Livewire.

Use case: I have a large number of sequential API calls running on the server, which collect data to populate a small spreadsheet-like table - this process takes several minutes, and I'd like to update the table in real time, filling in numbers in the browser as results are collected. The data is only intended for a single user.

I'm trying to weigh up the efficiency of polling from the browser versus the complexity of broadcasting with web sockets… on the face of it polling seems inefficient, but web sockets seems (much??) harder to learn, and also you can be broadcasting events which no-one might be listening to?

Links to any good blog posts or tutorials welcome. (Have already read this)

0 likes
1 reply
martinbean's avatar
Level 80

@wturrell Livewire isn’t going to be much help here if there’s a process running on the server and you want to update your page in realtime or near-realtime.

It depends what you need. Polling is just making a HTTP request on an interval. You’ll essentially be making a request and asking the server, “Give me all changes since X”. There may be no changes. There may be few changes. There may be many changes.

With web sockets (and broadcasting), you’ll receive a message when something changes without having to ask. You’ll also receive these events as and when these events happen. So events will always be of a similar size, but you may get no events for a long time and then many events in a burst if lots of things are updated in quick succession.

Please or to participate in this conversation.