我开发了一个比较网站,用于比较在印度在线销售的任何产品。目前,该站点完全是客户端:-
- Accepts user input.
- Makes 20-30 AJAX requests and fetches results from all the major online shops.
- Uses some client-side scripting to sort the results and show it in most appropriate way.
缺点:-
- My client side code is available to everyone. Its javascript.
- More prone to browser errors.
- Not robust.
使其成为服务器端后的缺点:-
- Considering the traffic of my website, server load will increase as it will be engaged with a client for longer time.
- Fetching values from various websites can take as much as 10s(at max).Server engaged for that time. Consider the load if I have 500 visitors/min at peak time.
优点:-
- My codes safe and secure
- Processing at client side will be minimum. Will work even on mobiles and other devices easily.
我想在实际实现之前分析这些问题。谁能建议我应该为我的网站选择什么?哪种方法更适合我?
如果我的问题不明确,请发表评论。
最佳答案
首先,这是一个很好的问题。
这完全取决于您的网站处理的数量和交易,如果您真的希望您的应用程序能够扩展,我希望您做对了!并从一开始就做好。
停止将您的业务逻辑放在客户端 ** 不要指望他进行比较时会占用最终用户的网络带宽 :) 也不要指望他拥有最好的带宽。
负载平衡您的服务器群 确保您的服务器群已正确负载平衡,并且比较是使用多线程而不是单线程完成的
缓存结果 ** 如果您在服务器端执行此操作,如果用户 a 和用户 b 请求相同的比较,您实际上可以从用户 b 的缓存中提取它,而不是再次执行这些请求。
可用性 向用户显示比较进度,而不是显示正在加载的旋转图像:)
希望对你有帮助
关于javascript - 服务器端处理还是客户端处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12596347/