Storage API
Local Storage and Session Storage
Few Important points:
1-Local Storage never expire.
2. Session storage expire when the user closes the browser tab. Each browser tab will have a separate session.
3. When you change local Storage data, an event gets fired that you can listen to. If user has open multiple tabs and changes a data that is being stored on in local storage. It will get updated for other browser tabs as well.
Facades:
A facades is a thin layer of abstraction around a native API. It is not a polyfill. It does not fill or add any new functionality on top of the existing api.
Frameworks are a more complex version of Facade. They add polyfill etc.
You should not use the Web APIs like Canvas API directly, you should either use a facade or a framework.
WebSocket API
An ajax request , from client to server and then back to server to client takes a total of 800 ms
roundtrip. So using Ajax for developing games or chats would be slow.
In a web socket, when we make the initial request, we keep the socket open which is listening. So next time we need an interchange of the data from server to client or vice versa , we don’t have to establish a new connection. Its a persistent socket.
Websocket header is smaller . Its only 8 bytes.So we are sending less data in the header. It makes it fast.
A websocket request could take upto 100 ms
.
We listen for an event using .on()
and then you send events back using .emit
() .So in websocket you send event back and forth. Both server and client can listen and send events. You can give a custom name to the events. You can also send data along with events.
Broadcasting
If a server wants to send a message to many users who have open socket port , instead of sending it through individual multiple request , it can broadcast that message.
Broadcasting is done on the server and not on the client.