What is the best way for loading data into different modules like iGoogle? I have three ideas, but which one is preferred?
- Generate the html page dynamical with the lastest data from the database.
- Serve a almost static html page, then the client fetch the data from a api with JavaScript
- Serve a almost static html page, then the client connects to a websocket which will provide the client with history data from the db before pushing the live-steams.
After one of these three cases the client connects (of course the third alternative will never disconnect) to a websocket which pushes live data.
Which alternative is the most preferred (fastest, most lightweight) and uses the techniques in the way they where meant? I have a feeling that the third alternative uses websockets in a wrong way?
My conclusion after some research and thinking;
Number 1:
- Can be used even if JavaScript is turned off
- We need to serve a dynamical page, with disk io
Number 2:
- Serves a fast html page
- Maximal number of connections (html page, api, websocket)
Number 3:
- Serves a fast html page
- We have minimal number of connections, since we will connect to the websockets even if the data is fetched before (html page, websocket)
If performance (and latency in particular) is important to you, going with solution 3 seems perfectly okay. Number 1 is nice for graceful degradation (as you’ve already noticed yourself), and perhaps number 2 is het most conceptually clean, but I think all solutions are fine.