Reputation: 3793
I have developed a comparison website for comparing any product sold online in India. Currently, the site is completely client side :-
- 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.
Disadvantages :-
- My client side code is available to everyone. Its javascript.
- More prone to browser errors.
- Not robust.
Disadvantages after making it server-side:-
- 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.
Advantages:-
- My codes safe and secure
- Processing at client side will be minimum. Will work even on mobiles and other devices easily.
I want to analyze about these issues before actually implementing them. Can anyone suggest me about what should I choose for my website ? Which approach will be better for me ?
Please comment if my question is ambiguous.
Upvotes: 4
Views: 3441
Reputation: 15099
I can't see why you are taking the "More prone to browser errors". Javascript will run exactly the way you want it if you send to the browser the correct libraries/code.
You can see what browser is doing the request and send it the right piece of code (read as: if you have some code that will work in FF & Opera but not IE, write two versions of that code, one for each group of browsers.) There are some libraries that can help you doing so.
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.
Upvotes: 1
Reputation: 2554
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
Upvotes: 3