Online dictionary - should I use AJAX for the search results?
I'm making an online dictionary. Now I have two options:
1) Use AJAX for retrieving results 2) Just use some regular PHP scripts
If I choose the first option more likely the online dictionary will have one page and it's fast. If I choose the second option I'll have more pages (separate page for each entry with it's own URL), but it's slower. Personally I like the second option, don't really like to much AJAX on pages.
What is your opinion? Cons and pros (for this certain case)?
开发者_开发问答Thank you.
If you use the second solution (ie, several URLs, one per page/definition), your users will be able to bookmark URLs for each specific page, use those to come back to youor site or link to it, or send them to other people, or whatever they want -- which is good.
If you only have one and only one page for your whole website, people cannot link to specific pages/definitions ; they have no way to come back to one specific word ; and that's bad :-(
Same for search engines, btw (Even if not that important for search results) : if they only see one page, they will not index your content well... and you probably want your site indexed.
So, in your case, I would probably go with several distinct URLs (even the corresponding pages are all generated by the same PHP script, of course).
And same thing for search results : you probably want to give people the ability to link to search results, don't you ?
About the "speed" thing : well, with Ajax, you'll send one request to the server. Without Ajax, you'll still send one request (for a bigger page, I admit), plus the ones for the images, CSS, JS, and all.
You should read a bit about Frontend optimization (see Yahoo's Exceptional Performance pages, for instance) ; it'll help quite a lot, about that ;-)
You could potentially use htaccess (assuming you're on a linux server) to give unique urls to each page which keeping one page for displaying content.
For instance:
http://yourdomain.com/s/sausage would point to http://yourdomain.com/page.php?id=426
Which then would pull from a db and show you the 426th result, which would be for sausage, hurray. You'd probably want to build a htaccess generator for this, or use a system of slugs and use regular expressions
htaccess would look like this:
$http://yourdomain.com/s/([^/]+)^ $http://yourdomain.com/page.php?slug=$1
this will send anything after http://yourdomain.com/s/ to page.php as a slug variable, then reference your database for that slug.
Not sure if that's in any way helpful.
精彩评论