使用 Backbone.js Pushstate 进行 SEO/书签时,重用服务器上的主干视图/路由
我正在对单页应用程序的主干进行一些尽职调查,想知道是否可以在服务器端重用来自客户端的相同视图/路由,以便当谷歌访问 Pushstate URL 或访问它时服务器可以直接生成与客户端中的主干生成的完全相同的 HTML。
必须维护两组独立的视图/路由,一组在客户端,一组在服务器上,这将是一件痛苦的事情。我已经在 github 上看到了 backnode 项目,但这似乎有点忽略了重点,你最终不得不编写相同的主干路由器两次。
只是想知道当在主干中使用 Pushstate url 并需要从服务器提供相同的视图时,人们通常如何处理这种情况?人们是在重复代码还是有更好的方法?
I'm doing some due diligence on backbone for a single page app and wonder if it is possible to re-use the same views/routes from the client on the server side, so that when google visits a pushstate URL, or it is accessed directly, the server can generate the exact same HTML that would be generated by backbone in the client.
It would be a pain to have to maintain two separate sets of views/routes, one on the client and one on the server. I have seen the backnode project on github however this seems to miss the point a bit and you end up having to write the same backbone router twice.
Just wondering how people are generally handling the case when using pushstate urls in backbone and needing to serve the same view from the server? Are people duplicating code or is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有尝试过,但是这些使用node.js和backbone的想法可能会有所帮助:
http://andyet.net/blog/2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/
http://bennolan.com/2010/08/13/pushstate-and-nodejs.html
基本上,避免重复编写相同内容的唯一方法是让 Node.js 服务器和前端客户端共享相同的路由/模型代码。如果您在服务器端使用其他东西(例如 Ruby),则必须将 node.js 放在应用程序服务器前面。然后为新客户端创建 node.js 代理(推送状态和客户端 js),并为旧客户端/机器人客户端执行实际渲染工作。
另一种选择是执行 jQuery Mobile 的操作,即 Hijax 方法。制作大量 HTML5 页面的想法(您必须查看其路由才能看到)。
为了完整起见,您应该了解 google 如何抓取 AJAX:http://code.google.com /web/ajaxcrawling/docs/getting-started.html
I haven't tried this yet but these ideas using node.js and backbone might help:
http://andyet.net/blog/2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/
http://bennolan.com/2010/08/13/pushstate-and-nodejs.html
Basically the only way to make it so your not writing the same thing twice is to have both your node.js server and frontend client share the same routing/model code. If you are using something else on the server side (like Ruby) you would have to place node.js in front of your app server. Then make node.js proxy for new clients (push state and client js) and do actually rendering work for old/bot clients.
The other option is doing what jQuery Mobile does which is the Hijax method. The idea to make tons of HTML5 pages (you'll have to look at its routing to see).
And for completeness you should be aware of how google crawls AJAX: http://code.google.com/web/ajaxcrawling/docs/getting-started.html
这个项目正是您想要做的。您可能有兴趣检查一下。
https://github.com/developmentseed/bones
This project does exactly what you are trying to do. It might interest you to check it out.
https://github.com/developmentseed/bones