将项目保存到收藏夹列表的最佳方法 - PHP、JS 还是组合?
我目前正在为一家招聘公司重新开发一个新网站。他们在网站上有数千个工作岗位,分为不同的职业、年级、专业和地点。
目前,该网站使用 PHP 构建所有页面,但将所有动态页面缓存在平面 html 中,以加快网站的加载速度。他们每隔几天更新数据库上的作业并擦除缓存以显示效果。
在该网站的新版本上,客户要求提供一项功能,允许用户将自己喜欢的工作保存在候选列表中。
我的问题是这样的。我知道我可以在 php 中很容易地做到这一点,但是这种方法需要放弃当前的缓存系统,因此它会减慢网站的速度(谷歌在其排名算法中越来越多地使用网站速度)。良好的有机搜索引擎性能在这方面的工作中至关重要。
我可以使用纯 JavaScript 构建一个职位候选名单系统 - 并允许它在您导航时跨页面共享数据吗?使用 cookies 可以吗?还是会议?该网站已经使用查询作为其 js 交互的基础。
或者说js和php的结合是最好的方法?
任何帮助规划此功能将不胜感激。我宁愿开始走上正确的道路,也不愿半途而废才意识到自己的错误!
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 increasingly 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,你可以用 JavaScript 来做到这一点。
我自己就是 Dojo 爱好者,但使用 jQuery 可以轻松完成。
看看 jquery 的 cookie 插件: https://github.com/carhartl/jquery-cookie
还可以看看 Backbone JS: http://documentcloud.github.com/backbone/#View
使用 Backbone 将允许您使用 MVC 设计模式创建列表。
具体查看待办事项列表示例: http://documentcloud.github.com/backbone /examples/todos/index.html
单击“查看带注释的源代码”以查看完整的带注释的源代码
对待办事项列表进行一些修改,您应该拥有您的工作列表。那么cookie插件就会让你坚持下去。
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.
正如 Ali 所说,你绝对可以使用 cookies 和 jquery 来做到这一点。
然而,需要考虑的一件事是数据将存储在特定计算机上,而不是用户的帐户中。因此,如果我在家浏览您的网站,并将一堆工作添加到我的候选名单中,然后开始工作并决定我要继续下去,我的候选名单就会消失。因此,虽然纯 js 和 cookie 解决方案很好,因为它不会干扰您当前的页面缓存系统,但它不会提供最佳的用户体验。
为此,您必须使用 php 并将入围名单存储在数据库中。不过,大多数 php 框架确实支持部分页面缓存。因此,您可以从 html 提供页面的大部分内容,然后添加一个动态生成的部分,这将是您的候选代码。这个解决方案可能需要更多工作,但最终会更好。
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.