最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Client Side vs Server Side When GET data from API - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 6

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 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.

发布评论

评论列表(0)

  1. 暂无评论