简体   繁体   English

JavaScript最佳实践:如何实现长期存在的应用程序(单页Web应用程序)?

[英]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.

相关问题 一页Web应用程序和内联JavaScript和CSS - One page web apps and inline javascript and CSS 使用Apache / PHP / Javascript的长期连接(异步服务器推送)? - Long-lived connections (asynchronous server push) with Apache/PHP/Javascript? 管理和部署大型 JavaScript 应用程序的最佳实践 - Best practices for managing and deploying large JavaScript apps 一页网站〜关于索引编制和社交媒体共享的最佳做法和方法 - One-page websites ~ Best practices & way to go regarding indexing and social media sharing Facebook 图 API 长寿命令牌 - Facebook Graph API Long-Lived Token 将短期访问令牌交换为长期有效 - Exchange short-lived access token for long-lived, not working 一页滚动导航无法使用Javascript吗? - One-page scroll nav not working with Javascript? 如何建立与jQuery的长期连接以进行推送通知? - How can I establish a long-lived connection with jQuery for push notification? Chrome扩展程序的长期消息连接-如何使用回调函数? - Chrome extension long-lived message connection - how to use callback functions? 如何在浏览器中获取JS代码的长期身份提供者令牌 - How to get long-lived indentity provider tokens for JS code in browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM