Search code examples
javascriptwebsocketwebhooksasyncsocket

Implement Webhook in Client-Side JavaScript?


I'm using some client-side JavaScript to make some API calls that return data to an end user. I'd like to use a Webhook (rather than polling the API) to get updated information from the API when it's available, but not sure if this is even since my JS is only client-side and has to be lightweight (e.g. I rather not rely on loading any libraries).

Would appreciate any pointers.


Solution

  • There is nothing wrong with loading libraries. Todays webpages heavily rely on libraries and albeit you can overdo it, loading a library is nothing which makes your page "heavy". You are better off doublechecking your image sizes when you optimize for size.

    For webhook implementations I would recommend websockets. A nice libarary for this purpose is socket.io. With websockets you can push data from the server to the client so you dont rely on polling.