问题
I had this question in my mind for a while.
So let's assume that we have a front-end server that has enough load and hit for just for sending files over the network to client.
Would you still say server-side rendering would make it more performant? or it will actually decrease it in this scenario (I ask this because actually maybe server has to do more processing which I believe has)
IMO the initial thoughts and idea of server-side rendering is your Front-End server is able to process the file and send it back faster than client computer? otherwise it's pointless???
I don't have strong opinion on this and that's why I asked it here :)
回答1:
Long story short sentence nothing is always efficient. Specially in computing world.
But as @Abhishek Mehandiratta mentioned the spirit of the Server-Side Rendering(SSR) is to decrease the initial render time. While decreasing the initial load has a huge impact in term of user experience its still has it's own trade off.
I would say the benefit that a company gets from efficiency and user experience of the initial render is far superior to the impact that is to the server load.
There is still a space for debate, it still depends on the requirements and the use case. Considering Facebook user-interface with 30 000 react component (including mobile and web) might be different to compare with a website that has only 100 component...
When it comes to scalability and availability of services and servers it gets quite tricky. In order to handle such a load and render time there is quite a bit of techniques that they are using.
- Lazy load components (code splitting)
- Concurrent rendering (it's more of a time slicing approach)
- Caching
- .... (and many more)
Previously apart from inital render time, server-side rendering had a HUGE benefit of Search Engine Optimisation(SEO) because web crawler couldn't crawl javascript generated pages. But most of the modern search engines are now crawling and capable of parsing javascript generated pages(read this if this topic interests you)
Also you will be able to learn from Walmart experience of migrating to a server-side rendering for their react front-end web.
回答2:
SSR makes your app performant by significantly decreasing the initial render time, but of course it comes at a price of increased load on the server. It depends on your app and the capability of the server whether you want to go for SSR or not. In case of react, renderToString method is sync. If you want to make this process async, react 16+ gives a method renderToNodeStream. I don't know about angular though.
来源:https://stackoverflow.com/questions/53808819/is-server-side-rendering-always-efficient