JavaScript 最佳实践:如何实现长寿命应用程序(单页 Web 应用程序)?
是否有实现长期 JavaScript 应用程序(即由单个页面组成并通过 AJAX 将其他页面加载到内容区域的 Web 应用程序)的最佳实践? (Gmail 就是一个很好的例子。)
我已经阅读了有关优缺点、SEO、性能等的内容(http://stackoverflow.com/questions/1499129/one-page-only-javascript-applications),我'我对如何实现这一点的模式感兴趣。
我想避免使用大型框架(例如 Cappuccino、Echo2、SproutCore、Claypool)。
如何管理动态加载内容,同时维护 URL 的 #link 部分(用于书签)?
不要误会我的意思,我自己有一个如何实现这个的想法,但这个问题之前肯定已经解决了。
有这方面的文章吗?也许是一个小型 JavaScript 库?
谢谢! 标记
Are there any best practices for implementing a long-lived JavaScript app, i.e. a web app that consists of a single page and loads other pages into the content area via AJAX? (Gmail is a good example of this.)
I already read about pro and cons, SEO, performance, etc. (http://stackoverflow.com/questions/1499129/one-page-only-javascript-applications), I'm interested in patterns how to implement this.
I'd like to avoid large frameworks (e.g. Cappuccino, Echo2, SproutCore, Claypool).
How would I manage dynamically loading content while maintaining the #link portion of the URL (for bookmarking)?
Don't get me wrong, I have an idea how to implement this myself, but this problem must have been solved before.
Are there articles on this? Maybe a tiny JavaScript library?
Thanks!
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现 JQuery Address http://www.asual.com/jquery/address/ 非常简单来设置。
$.address.change()
让您知道何时点击了某些内容(也适用于来回),您只需解析self.location.hash
并构建您的应用程序从那里。如果您可以使用 JQuery 进行处理,它看起来也足够轻量。I found JQuery Address http://www.asual.com/jquery/address/ extremely easy to set up.
$.address.change()
let's you know whenever something was clicked (works with back and forth as well) and you just parseself.location.hash
and build your app from there. It seems lighweight enough as well, if you can handle using JQuery.这里有一篇文章可以帮助您解决历史书签问题:http: //codinginparadise.org/weblog/2005/09/ajax-dhtmlhistory-and-historystorage.html。它已经很旧了,但解决方案仍然有效。
我使用这个“长寿”应用程序制作了几个应用程序,您应该考虑的一件事是 IE 泄漏内存的倾向。
我还建议您使用 JS 库(例如 JQuery)来帮助您使用 AJAX 和 DHTML。
Here is an article to help you with the History bookmarks problem: http://codinginparadise.org/weblog/2005/09/ajax-dhtmlhistory-and-historystorage.html. It's quite old, but the solution still works.
I made several apps using this "long lived" apps, and one thing you should take into account is IE's tendency to leak memory.
I would also recommend you to use a JS library, like JQuery to help you with the AJAX and DHTML.
听说过 JavaScript PushState 吗?
http://badassjs.com/post/840846392 /location-hash-is-dead-long-live-html5-pushstate
它的目的是替换 location.hash
Heard about javascript pushstate?
http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate
It's meant to replace location.hash