Skip to content

Instantly share code, notes, and snippets.

@yitznewton
Created June 10, 2014 11:10
Show Gist options
  • Select an option

  • Save yitznewton/41cc6a25493ff1a6f0b0 to your computer and use it in GitHub Desktop.

Select an option

Save yitznewton/41cc6a25493ff1a6f0b0 to your computer and use it in GitHub Desktop.
WebSockets and AJAX: an initial comparison

WebSockets and AJAX: an initial comparison

AJAX (i.e. HTTP) advantages

  • namespacing (URL)
    • WebSockets only have global events
      • might actually be global ("shut down server")
      • might be context-sensitive ("add an item to the current to-do list")
  • request & response cycle, with semantics
    • WebSockets only have one-off messages
      • intrinsically carry the same meaning whether sent from the server or client
      • responding to a specific message is outside the scope of the protocol
  • protocol includes provision for metadata (headers)

WebSockets advantages

  • persistent connection with state
    • no need to directly manage session state
      • reconstructing session state from a data store
      • validating currency of session between server and client
        • cf. "when user logs out in client, server must destroy session"

Shared disadvantages

  • data payloads are untyped strings
    • application must estabish its own convention for enforcing type
      • parsing & validation
      • error response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment