Bad practice sending HTML over a WebSocket connection

I am developing a small application in Node.js with a MongoDB database, I have nginx to handle static files and the original index.html.

When I am in my index.html, all javascript / css / img files are uploaded and the connection to the server is done on the Node.js server.

Initially, my index.html is empty, you need to fill it with the correct template file. One thing I could do is make normal ajax req.

$. get ('myfile.html') and add it to my content. Websocket processes database data.


Now I already have an open connection to the server on the server, why not just transfer the .html template along with the data from the database and combine it in the client.

Template files are just small html fragments, why waste http req, right?


Please note that this application will only be used by select people with full html5 browser support. No backup situations are required.

+6
source share
1 answer

Given that HTTP is so well suited for working with files, caching - perhaps in several layers - works for you, so you donโ€™t even have to send any html content more than once to a visitor, I definitely think that the excesses outweigh the disadvantages . It looks like you can send index.html along with related content and have templates in your index.html (for example, like in jQuery templates , which can use the <script id="fooTemplate" type="text/x-jquery-tmpl"> ).

Obviously, you can send templates via WebSocket.

+5
source

Source: https://habr.com/ru/post/910974/


All Articles