admin 管理员组文章数量: 1086019
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.
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.
Share Improve this question asked Feb 28, 2017 at 19:04 userMod2userMod2 9,00217 gold badges73 silver badges134 bronze badges 4- 1 If there is an API key involved, you should do server side. Always remember that any function or variable that is not anonymous can be seen by the client. If you want to make the request asynchronously, make an asynchronous request from your client to your server, which then makes the request to the api. – 01010011 01000010 Commented Feb 28, 2017 at 19:15
- You cannot make AJAX calls(from client side) if the data is in a different server. You will get cross browser scripting error – Sharjeel Ahmed Commented Feb 28, 2017 at 19:35
- 1 @SharjeelAhmed — Wrong. We've had JSONP since 2005 and CORS (in draft form at least) since 2006. – Quentin Commented Feb 28, 2017 at 19:43
- I am not sure JSONP works for post calls. – Sharjeel Ahmed Commented Mar 1, 2017 at 7:01
2 Answers
Reset to default 6Is 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 es from a different puter which might be nearer or further from the server the request is being made to. This might be faster.
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.
本文标签: javascriptClient Side vs Server Side When GET data from APIStack Overflow
版权声明:本文标题:javascript - Client Side vs Server Side When GET data from API - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744061644a2526829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论