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

javascript - Processing file on front-end vs back-end - Stack Overflow

programmeradmin2浏览0评论

I am developing a web application with angularjs as the front-end and a CRUD service at the backend. One of the requirements is to allow the user to upload a csv file containing a list of items to be created. This can be implemented on the front-end by parsing the file in javascript and making create API call to the server for each item. However, I am an not sure if this approach is better than passing the file to the server and doing all the processing there. What are advantages/disadvantages of both these approaches? What is the common practice in such a scenario?

I am developing a web application with angularjs as the front-end and a CRUD service at the backend. One of the requirements is to allow the user to upload a csv file containing a list of items to be created. This can be implemented on the front-end by parsing the file in javascript and making create API call to the server for each item. However, I am an not sure if this approach is better than passing the file to the server and doing all the processing there. What are advantages/disadvantages of both these approaches? What is the common practice in such a scenario?

Share Improve this question edited Aug 4, 2015 at 13:52 vjain27 asked Aug 4, 2015 at 13:47 vjain27vjain27 3,6749 gold badges43 silver badges61 bronze badges 3
  • What is the supposed format of the file? e.g. xls, txt, doc etc. – Ivan Sivak Commented Aug 4, 2015 at 13:50
  • Sorry, forgot to mention. It will be a csv file. Edited the question. – vjain27 Commented Aug 4, 2015 at 13:53
  • I believe it's better to upload the file to the server and import/process to database on the server. If you would process it on client side you would need to issue http request for every record and this would create useless http traffic. Of course, you could convert csv to json and send just this one json over one http request but since both are in fact simple text formats I would go with csv being processed on the server. EDIT: Also, if you're using e.g. sql server you could do sql bulk insert accordingly – Ivan Sivak Commented Aug 4, 2015 at 13:59
Add a comment  | 

3 Answers 3

Reset to default 11

There are 4 things that I would use to make this decision:

  1. Do you have very high load. If you parse it on the client you are using the clients CPU. Parsing it on the server could cost you by needing more CPU's.

  2. Access to developer talent, is your team more productive programming it on the client or the server side.

  3. If the answer to the above does not give a clear answer, then I would put it on the server side as it would be easier to test.

  4. Will the "upload TSV" functionality be used by other parties/apps, who consume your API -- or is only the frontend using this functionality ?

Since I have implemented this scenario, couldn't resist from responding. I believe following things would be considered(Addition to points mentioned above) :

  1. The Size of the file, (Huge files freeze UI, no brainer) it can even crash some not so modern browsers.
  2. Does the file need parsing/sanitizing the contents?( you would not want the garbage to make its way to your server)
  3. Does the User need a feedback of the load summary details after the upload?(Aync vs Sync) - This tied back to #1

Regardless, you'll end up using some variation of the bulk copy at the backend.

Well I think its advisable to parse files at the backend. You get so many options like

  1. saving the file for reference
  2. reducing the load on your user's resource (RAM and CPU depending on the size of the file and the operation being done on the file before pushing to backend)
  3. Can re-initiate activity on file if there is an error during batch( if the error is code you can reproduce and help out client because you've got the file
发布评论

评论列表(0)

  1. 暂无评论