[英]JavaScript Best Practices: How to implement long-lived apps (one-page web apps)?
Are there any best practices for implementing a long-lived JavaScript app, ie a web app that consists of a single page and loads other pages into the content area via AJAX? 是否有任何最佳实践来实现一个长期存在的JavaScript应用程序,即一个由单个页面组成的Web应用程序,并通过AJAX将其他页面加载到内容区域? (Gmail is a good example of this.)
(Gmail就是一个很好的例子。)
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. 我已经阅读了关于pro和cons,SEO,性能等的内容(http://stackoverflow.com/questions/1499129/one-page-only-javascript-applications),我对模式如何实现这一点感兴趣。
I'd like to avoid large frameworks (eg Cappuccino, Echo2, SproutCore, Claypool). 我想避免使用大型框架(例如Cappuccino,Echo2,SproutCore,Claypool)。
How would I manage dynamically loading content while maintaining the #link portion of the URL (for bookmarking)? 如何在维护URL的#link部分(用于书签)的同时动态加载内容?
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?
也许是一个很小的JavaScript库?
Thanks! 谢谢! Mark
标记
Here is an article to help you with the History bookmarks problem: http://codinginparadise.org/weblog/2005/09/ajax-dhtmlhistory-and-historystorage.html . 这篇文章可以帮助您解决历史书签问题: 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. 我使用这个“长寿”应用程序制作了几个应用程序,你应该考虑的一件事是IE倾向于泄漏内存。
I would also recommend you to use a JS library, like JQuery to help you with the AJAX and DHTML. 我还建议你使用JS库,比如JQuery来帮助你使用AJAX和DHTML。
Heard about javascript pushstate? 听说过javascript pushstate?
http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate
It's meant to replace location.hash 这意味着要替换location.hash
I found JQuery Address http://www.asual.com/jquery/address/ extremely easy to set up. 我发现JQuery Address http://www.asual.com/jquery/address/非常容易设置。
$.address.change()
let's you know whenever something was clicked (works with back and forth as well) and you just parse self.location.hash
and build your app from there. $.address.change()
让你知道每当被点击的东西(也来回工作)你只需解析self.location.hash
并从那里构建你的应用程序。 It seems lighweight enough as well, if you can handle using JQuery. 如果你可以使用JQuery处理它似乎也足够轻量级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.