Tips and tricks

Let's talk about some tips and tricks that you can use while making an application.

  • Using JSON:

    The JSON format is an easily readable format in JavaScript. It is always good to transfer data in the JSON format.

  • Object-based structure for WebSockets:

    Normally, in any application where we have to transfer different data sets, it is always preferred that we finalize a proper structure for the messages. Take the example of a chatting application: if we finalize a structure, it is better to handle the message. Here is a sample structure:

      {
        type: "message"
        data : {
          from: "varun"
          to : "user1"
          data : "hello"
               }
      }
  • Using ArrayBuffer:

    There is another way to send data using ArrayBuffer; you can also send a Binary Large Object (BLOB). Here is an ...

Get WebSocket Essentials – Building Apps with HTML5 WebSockets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.