4

我开发了一个比较网站,用于比较在印度在线销售的任何产品。目前,该网站完全是客户端:-

  1. 接受用户输入。
  2. 发出 20-30 个 AJAX 请求并从所有主要在线商店获取结果。
  3. 使用一些客户端脚本对结果进行排序并以最合适的方式显示。

缺点:-

  1. 我的客户端代码可供所有人使用。它的JavaScript。
  2. 更容易出现浏览器错误。
  3. 不健壮。

使其成为服务器端后的缺点:-

  1. 考虑到我网站的流量,服务器负载会增加,因为它将与客户端接触更长时间。
  2. 从各种网站获取值可能需要多达 10 秒(最多)。当时使用的服务器。如果我在高峰时间有 500 名访客/分钟,请考虑负载。

好处:-

  1. 我的代码安全可靠
  2. 客户端的处理将是最少的。甚至可以在手机和其他设备上轻松工作。

我想在实际实施之前分析这些问题。谁能建议我应该为我的网站选择什么?哪种方法对我更好?

如果我的问题模棱两可,请发表评论。

4

2 回答 2

4

Well first of all thats a very nice question.

it completely depends on the volume and transactions your site handles and if you really want your application to scale, i wish you do it right! and do it right from the beginning.

Stop putting your business logic on the client side ** dont expect to eat end user network bandwidth when he makes a comparison call :) and dont expect he has the best bandwidth.

Load balance your server farm make sure your server farm is properly load balanced and the comparison is done using multi threads instead in a single thread

cache results ** if you are doing this on the server side, if user a and user b asks for the same comparison you can actually pull it from the cache for user b instead doing these requests again.

Usability show the progress of comparison to user instead showing a loading spinning image :)

hope it helps

于 2012-09-26T07:23:59.180 回答
2

我不明白您为什么选择“更容易出现浏览器错误”。如果您向浏览器发送正确的库/代码,Javascript 将完全按照您想要的方式运行。

您可以查看哪个浏览器正在执行请求并向其发送正确的代码(读作:如果您有一些代码可以在 FF 和 Opera 但不能在 IE 中运行,请编写该代码的两个版本,一个用于每组浏览器.) 有一些库可以帮助您这样做。

Also, a comparison is not anything that should be done on the server side. SO, if you have a lot of traffic on your website, client-side work should be fine for that kind of stuff.

About the code-protection, you're right. Server-side won't let anybody read your code. So you must decide if server load is more important than people reading your code.

Also keep in mind that you can obfuscate your code. I know that's not the best solution, but it will keep away a lot of people not reading it.

EDIT:

Making it server side will make things work as expected on all devices (as your already said). But there are some things you need to do in order to preserve your server's load from going to 100%.

Chandra Sekhar Walajap already told you about the benefit of using some kind of cache for the results. I'd personally go a little bit further as you're just scraping all those pages.

I'd create a scraper that will run, let's say, every 24 hours and fetch/scrape each product. Then I'd save all those products somewhere (read as in a database or whatever you want). This way, when a user makes a request for a comparison between products A and B you won't need to fetch/scrape all the sites, instead of that you'll just have to look for those products in the place where you saved them and show them to the user.

Note that this will preserve a lot of bandwidth only if you have a lot of users comparing a lot of products.

On the other side, if you have a few users searching only for a few products, making that kind of solution won't benefit you at all, because you know, fetching everything from all the sites every 24 hours is a lot of usage, both in CPU and bandwidth.

About the server load: I can't say. It depends on so much things that it's nearly impossible to say. You need to consider how big are the website that you're scraping , how many products are there on each website? What's the hardware you're using? You'd be better by making some simple example using cURL and fetching everything from one of the sites. Then see how that impacts on the performance and decide.

于 2012-09-26T07:19:37.693 回答