问题
I'm retrieving data from a movie API.
Now i can either do this in on client side (jQuery) or can make the http get call on the server side (Node.js).
Is there a best practice in doing this? Is one option faster than the other?
(I'm towards server side as I can hide my API key) but interested to know for certain.
回答1:
Is there a best practice in doing this?
Not a general one
Is one option faster than the other?
Doing it server side allows results to be cached and shared between multiple clients. This might be faster.
Doing it server side allows the client to make one fewer HTTP requests. This might be faster.
Doing it client side allows it to be redone without reloading the whole page. This might be faster.
Doing it client side means it comes from a different computer which might be nearer or further from the server the request is being made to. This might be faster.
回答2:
Concerning hiding your API key, if you are using NodeJS, it doesn't matter whether you make calls from client side or server side, you have the control of not exposing your API key.
Concerning performance, I would propose to check out different opinions on the internet for the topic "Client Side VS Server Side rendering". There are a lot of articles related to performance. This is one them. Hope it helps.
来源:https://stackoverflow.com/questions/42516798/client-side-vs-server-side-when-get-data-from-api