总的来说:仅 JS 与基于页面的 Web 应用程序
当开发 Web 应用程序(而不是网站)时,有什么理由使用多个 HTML 页面,而不是使用一个 html 页面并通过 Javascript 完成所有操作?
我希望这取决于应用程序——也许——但我会感激关于这个主题的任何想法。
提前致谢。
编辑:
根据这里的回复以及我自己的一些研究,如果您想做一个单页、完全由 JS 驱动的网站,一些有用的工具似乎包括:
JQuery 插件:
jQuery 历史: http://balupton.com/projects/jquery-history
JQuery 地址: http://plugins.jquery.com/project/jquery-address
JQuery 分页: http://plugins.jquery.com/project/pagination
框架:
可能是 JMVC: http://www.javascriptmvc.com/
When a developing a web app, versus a web site, what reasons are there to use multiple HTML pages, rather than using one html page and doing everything through Javascript?
I would expect that it depends on the application -- maybe -- but would appreciate any thoughts on the subject.
Thanks in advance.
EDIT:
Based on the responses here, and some of my own research, if you wanted to do a single-page, fully JS-Powered site, some useful tools would seem to include:
JQuery Plug Ins:
JQuery History:
http://balupton.com/projects/jquery-history
JQuery Address:
http://plugins.jquery.com/project/jquery-address
JQuery Pagination:
http://plugins.jquery.com/project/pagination
Frameworks:
Sproutcore
http://www.sproutcore.com/
Cappucino
http://cappuccino.org/
Possibly, JMVC:
http://www.javascriptmvc.com/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
基于页面的应用程序提供:
它们还提供以下功能(尽管许多 js 框架可以解决这些问题):
page based applications provide:
they also provide the following (although these are solvable by many js frameworks):
更大的原因之一是您的网站的可搜索性。
在 JavaScript 中完成所有操作都会使搜索引擎抓取网站的所有内容变得复杂,从而无法对其进行完全索引。有很多方法可以解决这个问题(使用 Google 最近的 AJAX SEO 指南),但我不确定是否所有搜索引擎都支持这一点。最重要的是,它比制作单独的页面要复杂一些。
更大的问题是,无论您决定构建多个 HTML 页面,还是决定使用某种框架或 CMS 来生成它们,网站的不同部分都有其唯一的 URL。例如,“关于”部分将具有类似 mywebsite.com/about 的 URL,并且该 URL 用于网站内实际的“关于”链接。
One of the bigger reasons is going to be how searchable your website is.
Doing everything in javascript is going to make it complicated for search engines to crawl all content of your website, and thus not fully indexing it. There are ways around this (with Google's recent AJAX SEO guidelines) but I'm not sure if all search engines support this yet. On top of that, it's a little bit more complex then just making separate pages.
The bigger issue, whether you decide to build multiple HTML pages, or you decide to use some sort of framework or CMS to generate them for you, is that the different sections of your website have URL's that are unique to them. E.g., an about section would have a URL like mywebsite.com/about, and that URL is used on the actual "about" link within the website.
单页、Ajax 化网站的最大缺点之一是复杂性。原本可能分布在多个页面上的内容突然变成了一个巨大的母版页。此外,协调页面的状态(例如,跟踪您是否处于编辑模式或预览模式等)并调整界面以匹配也可能很困难。
此外,如果一个母版页需要加载多个 JS 文件,那么它可能会拖累性能。
One of the biggest downfalls of single-page, Ajax-ified websites is complexity. What might otherwise be spread across several pages suddenly finds its way into one huge, master page. Also, it can be difficult to coordinate the state of the page (for example, tracking if you are in Edit mode, or Preview mode, etc.) and adjusting the interface to match.
Also, one master page that is heavy on JS can be a performance drag if it has to load multiple, big JS files.
应 OP 的要求,我将讨论我在纯 JS 网站上的经验。我已经编写了四个相关站点:两个 JS 重站点(Slide 和 SpeedDate) 和两个纯 JS (Yazooli 和GameCrush)。请记住,我是一个只支持 JS 的网站偏执狂,所以您基本上是在阅读 John Hinkley 关于 Jody Foster 的主题。
我什么时候不只使用 JS?如果我正在制作一个几乎完全是内容的网站,用户除了从一个地方导航到另一个地方之外什么都不做,从不以复杂的方式与网站进行交互。所以,维基百科和......嗯,就是这样。一个很大的参考网站,有很多数据供用户阅读。
At the OP's request, I'm going to discuss my experience with JS-only sites. I've written four relevant sites: two JS-heavy (Slide and SpeedDate) and two JS-only (Yazooli and GameCrush). Keep in mind that I'm a JS-only-site bigot, so you're basically reading John Hinkley on the subject of Jody Foster.
When would I not use JS-only? If I were producing a site that was almost entirely content, where the user did nothing but navigate from one place to another, never interacting with the site in a complicated manner. So, Wikipedia and ... well, that's about it. A big reference site, with a lot of data for the user to read.
模块化。
多个文件允许您更清晰地划分不同的工作流程路径和流程部分。
您的业务规则通常不会直接影响您的布局规则,并且多个文件可以更好地帮助编辑需要编辑的内容,而不会有破坏不相关内容的风险。
modularization.
multiple files allows you to mre cleanly break out different workflow paths and process parts.
chances are your Business Rules are something that do not usually directly impact your layout rules and multiple files would better help in editing on what needs to be edited without the risk of breaking something unrelated.
实际上,我刚刚仅使用一个页面开发了我的第一个应用程序。
..它变得混乱
我的想法是创建一个尽可能模仿桌面环境的应用程序。特别是,我希望在弹出窗口中显示一些应用程序数据的详细视图,无论它们位于应用程序的哪个部分,都可以保持其状态。
因此,我的弗兰肯斯坦诞生了。
由于预算/时间限制,最终发生的事情是代码失控。我的 JavaScript 源代码的各个部分都混在一起了。事实证明,保持各种观点的正确状态是……困难的。
通过适当的规划和技术,我认为“一页”方法是一种非常简单的方法,可以打开一些非常有趣的可能性(例如:跨应用程序部分维护状态的小部件)。但它也打开了许多...许多潜在问题领域。包括...
我确信还有更多...
简而言之,我强烈建议您不要仅仅因为兼容性问题而依赖 JavaScript。我逐渐意识到,根本不需要依赖 JavaScript 来完成一切。
我实际上正在删除 渐进增强。这更有意义。您可以使用正确编码的 JavaScript 实现相同或相似的效果。
这个想法太...
使用渐进式增强,人们可以开发一个提供以下功能的应用程序 为用户提供尽可能最好的体验。
I actually just developed my first application using only one page.
..it got messy
My idea was to create an application that mimicked the desktop environment as much as possible. In particular I wanted a detailed view of some app data to be in a popup window that would maintain it's state regardless of the section of the application they were in.
Thus my frankenstein was born.
What ended up happening due to budget/time constraints was the code got out of hand. The various sections of my JavaScript source got muddled together. Maintaining the proper state of various views I had proved to be... difficult.
With proper planning and technique I think the 'one-page' approach is a very easy way to open up some very interesting possibilities (ex: widgets that maintain state across application sections). But it also opens up many... many potential problem areas. including...
I'm sure there are more...
In short, I would urge you to stay away from relying on JavaScript dependency for the compatibility issue's alone. What I've come to realize is there is simply no need rely on JavaScript to everything.
I'm actually in the process of removing JavaScript dependencies in loo of Progressive Enhancement. It just makes more sense. You can achieve the same or similar effects with properly coded JavaScript.
The idea is too...
Using Progressive Enhancement one can develop an application that delivers the best possible experience for the user that is possible.
对于一些其他论点,请查看《单页界面宣言》以及 Hacker News 上对其的一些(大部分)负面反应(链接位于 SPI 页面底部):
《单页界面宣言》:http://itsnat.sourceforge.net/php/spim/spi_manifesto_en.php
For some additional arguments, check out The Single Page Interface Manifesto and some (mostly) negative reaction to it on Hacker News (link at the bottom of the SPI page):
The Single Page Interface Manifesto: http://itsnat.sourceforge.net/php/spim/spi_manifesto_en.php
stofac,首先,感谢您提供单页接口(SPI)宣言的链接(我是这篇无聊文本的作者)
说了这一点,SPI!=通过Javascript做所有事情
看看这个例子(以服务器为中心) ):
http://www.innowhere.com/insites/
GAE 中相同:
http://itsnatsites.appspot.com/
有关 GAE 方法的更多信息:
http://www.theserverside.com/news/thread.tss?thread_id=60270
在我看来,完全用 JavaScript 编写一个复杂的 SPI 应用程序/网站是非常非常复杂和有问题的,我认为最好的方法是 SPI 的“混合编程”,以服务器为中心的大状态管理和以客户端为中心(也称为手动 JavaScript)以获得特殊效果。
stofac, first of all, thanks for the link to the Single Page Interface (SPI) Manifesto (I'm the author of this boring text)
Said this, SPI != doing everything through Javascript
Take a look to this example (server-centric):
http://www.innowhere.com/insites/
The same in GAE:
http://itsnatsites.appspot.com/
More info about the GAE approach:
http://www.theserverside.com/news/thread.tss?thread_id=60270
In my opinion coding a complex SPI application/web site fully on JavaScript is very very complex and problematic, the best approach in my opinion is "hybrid programming" for SPI, a mix of server-centric for big state management and client-centric (a.k.a JavaScript by hand) for special effects.
在单个页面上使用 ajax 到处执行所有操作会破坏浏览器的历史记录/后退按钮功能,并且会让用户感到厌烦。
Doing everything on a single page using ajax everywhere would break the browser's history/back button functionality and be annoying to the user.
我完全鄙视那些不需要 JS 的网站。这个额外的条件使一切变得不同。以经常引用的 Google Docs 为例,在这种情况下,它不仅有助于改善体验,而且至关重要。但 Google 帮助的某些部分是纯 JS 的,但它没有给体验带来任何好处,它只显示静态内容。
以下是我感到不安的原因:
显然,这意味着您网站的某些访问者要么会被拒绝,要么因需要提供临时排除而感到困扰。这会减少你的观众。
但它使用 JS 是没有意义的,大多数内容都是静态的。 “页面”仍在获取(通过 AJAX),因此延迟是相同的。借助 AJAX 的优势,它应该在后台轮询以检查更改,但当可见页面被修改时我不会收到通知。各个部分具有不同的样式,因此在遍历这些部分时会出现尴尬的重新渲染,通过 Javascript 加载外部样式表是糟糕的做法。为了“看看我们的 Web 2.0”功能而牺牲了易用性。这样的面向业务的应用程序应该注重检索速度,但结果却变慢了。
最终我不得不拒绝使用它,因为它扰乱了团队的工作流程。这不利于客户与供应商的关系。
正如其他答案中提到的,“渐进增强”,née“Unobtrusive Javascript”,是更好的方法。当我被要求制作一个纯 JS 的网站时(记住,我原则上不反对它,而且有时它是有效的)我期待实现前面提到的 AJAX 爬行,并希望它在未来变得更加标准化。
I utterly despise JS-only sites where it is not needed. That extra condition makes all the difference. By way of example consider the oft quoted Google Docs, in this case it not only helps improve experiences it is essential. But some parts of Google Help have been JS-only and yet it adds nothing to the experience, it is only showing static content.
Here are reasons for my upset:
Obviously this means some visitors to your site are either going to be turned away or feel hassled by the need to provide a temporary exclusion. This reduces your audience.
But it's use of JS is pointless, most content is static. "Pages" were still being fetched (via AJAX) so the delay is the same. With the benefit of AJAX it should be polling in the background to check for changes but I wouldn't get notified when the visible page had been modified. Sections had different styles so there was an awkward re-rendering when traversing those, loading external stylesheets by Javascript is Bad Practice™. Ease of use was sacrificed for whizz-bang "look at our Web 2.0" features. Such a business-orientated application should concentrate on speed of retrieval, but it ended up slower.
Eventually I had to refuse to use it as it was disrupting the team's work flow. This is not good for client-vendor relationships.
As mentioned in other answers the "Progressive Enhancement", née "Unobtrusive Javascript", is the better approach. When I am required to make a JS-only site (remember, I don't object to it on principle and there are times when it is valid) I look forward to implementing the aforementioned AJAX crawling and hope it becomes more standardised in future.