6

I am currently helping to design a web site and application in HTML. We would like the user to be able to search the site/app for desired content via a search bar. We would also like to include an advanced search ability to allow for different search options and more concentrated searches.

We are having trouble deciding whether to program the search function on the Client-Side (with JavaScript) or on the Server-Side (with PHP). What are the pros and cons of both and what would you recommend?

2
  • 7
    Unless you're searching content already on the page, won't you need some sort of back-end to populate the data even if you perform the search in JS? Commented Oct 29, 2012 at 14:45
  • 2
    If you meant what you said and you're searching the site then don't be foolish and ship all of your content to the client just so that you can search it there... that'd be a colossal waste of bandwidth. Commented Oct 29, 2012 at 15:14

2 Answers 2

3

As others have commented on your question, you need server-side functionality to provide effective and efficient search in a website; otherwise you would need to make all searchable content available to the client-side search engine; unless the volume of searchable content was very small, this would be troublesome.

Once you have the server-side functionality, yes, you can add AJAX to make searching niftier- esp. autocomplete functionality, quick filtering, etc., although that's also going to rely on the server-side functionality.

My personal point of view; if you do have the time to do AJAX and it adds speed, do so. But it is time-consuming and perhaps your time would be better spent some place else.

2

I think this is leaning more towards a user experience sort of question, but I want to mention one thing before I go into that. If you're searching things that you have already loaded into the page, then using JS will probably be your best bet since you'll be searching records that the server side has already fetched and given to the page. Now if that isn't the case, then I think your issue is more UX.

If the content your searching isn't already on the page, then you could have the call to the search on the client side, but you'll still need some server-side logic to fetch the records for the client to render. The big question is, do you want the user to sit through a page load, or would you rather render the results on the same page?

At work, we have both types of searches being used. We have a search box to search for users and it retrieves minimal amount of info about the users and constructs a dropdown based on the text in the input. But you can also submit that search, and you will be directed to a page that displays more information about the search results.

This is really less of a, which one is better for performance/developments/etc. and more about how you want the user to interact with your search. I believe that either way, you'll need some sort of server-side code, but how you display that is completely up to you and your UX goal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.