开发者

Best method for saving items to a favourites list - PHP, JS, or a combination?

I'm currently redeveloping a new website for a recruitment company. They have thousands of jobs on the site, split into different professions, grades, specialties, and locations.

At the moment the site builds all the pages using PHP, but caches all the dynamic pages in flat html to speed up the loading of the site. They update the jobs on the database every few days and wipe the cache for the effects to show up.

On the new version of the site the client has a requested a feature which allows users to save their favourite jobs in a shortlist.

My question is this. I know I can do this quite easily in php, but this method would require ditching the current cache system so it'd slow the site down (and google is in开发者_开发百科creasingly using a websites speed in its ranking algorithm). Good organic search engine performance is paramount in this line of work.

Can I build a job shortlist system using pure javascript - and allow it to share the data across the pages as you navigate? Is that possible using cookies? Or sessions? The site is already using query as a base for its js interactions.

Or is the best method a combination of js and php?

Any help planning this feature would be greatly appreciated. I'd rather start on the correct path than get halfway down before realising my mistake!


Yes you can do this with javascript. I'm a Dojo guy myself, but it's easily done using jQuery.

have a look at the cookie plugin for jquery: https://github.com/carhartl/jquery-cookie

also have a look at Backbone JS: http://documentcloud.github.com/backbone/#View
using Backbone will allow you to create the list using an MVC design pattern.
specifically check out the todo list example: http://documentcloud.github.com/backbone/examples/todos/index.html
click 'View the annotated source' to see the full, annotated source code

with some modification of the todo list, you should have your job list. Then the cookie plugin will get you your persistence.


As Ali said, you can definitely do this using cookies and jquery.

One thing to consider, however, is that the data will be stored on a particular computer, not in the user's account. So if I am at home browsing your site, and add a bunch of jobs to my shortlist, then go into work and decide I want to keep at it, my shortlist will be gone. So while the pure js and cookie solution will be nice in that it won't interfere with your current page cache system, it won't provide an optimal user experience.

To do that, you'll have to php and store the shortlist in your database. Most php frameworks do support partial page caching, though. So you could serve up the majority of the page from html, and then add in the one dynamically generated section which would be your shortlist code. This solution will probably be more work but better in the end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜