总的来说:仅 JS 与基于页面的 Web 应用程序

发布于 2024-10-09 04:18:03 字数 993 浏览 5 评论 0原文

当开发 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

框架:

芽核 http://www.sproutcore.com/

卡布奇诺 http://cappuccino.org/

可能是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

好听的两个字的网名 2024-10-16 04:18:03

基于页面的应用程序提供:

  • 在任何浏览器或设备上工作的能力
  • 更简单的编程模型

它们还提供以下功能(尽管许多 js 框架可以解决这些问题):

  • 可书签性
  • 浏览器历史
  • 记录刷新或 F5 重复操作
  • 可索引性(如果应用程序是公共的并且打开)

page based applications provide:

  • ability to work on any browser or device
  • simpler programming model

they also provide the following (although these are solvable by many js frameworks):

  • bookmarkability
  • browser history
  • refresh or F5 to repeat action
  • indexability (in case the application is public and open)
祁梦 2024-10-16 04:18:03

更大的原因之一是您的网站的可搜索性。

在 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.

离笑几人歌 2024-10-16 04:18:03

单页、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.

予囚 2024-10-16 04:18:03

应 OP 的要求,我将讨论我在纯 JS 网站上的经验。我已经编写了四个相关站点:两个 JS 重站点(SlideSpeedDate) 和两个纯 JS (YazooliGameCrush)。请记住,我是一个只支持 JS 的网站偏执狂,所以您基本上是在阅读 John Hinkley 关于 Jody Foster 的主题。

  1. 这个想法确实有效。它以非常低的运营成本生成优雅的响应式网站。我的估计是,带宽、CPU 等成本占运行类似的基于页面的网站成本的 10%。
  2. 您需要更少但更好(或者至少是训练有素)的程序员。 JavaScript 是一种强大且优雅的语言,但它也存在一些像 Java 这样更加僵化和缺乏想象力的语言所没有的巨大问题。如果您有一大堆基本平庸的人为您工作,请考虑 JSP 或 Ruby,而不是仅使用 JS。如果要求你使用PHP,就自己拍吧。
  3. 您必须在锚标记中保留基本会话状态。用户只是期望 URL 代表站点的状态:重新加载、添加书签、后退、前进。 jQuery 的地址插件将为您做很多工作。
  4. 如果 SEO 对您来说是个问题,请研究 Google Ajax 抓取。基本上,您创建一个非常简单的并行站点,仅用于搜索引擎。

我什么时候只使用 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.

  1. The idea really works. It produces gracefully, responsive sites at very low operational costs. My estimate is that the cost for bandwidth, CPU, and such goes to 10% of the cost of running a similar page-based site.
  2. You need fewer but better (or at least, better-trained) programmers. JavaScript is an powerful and elegant language, but it has huge problems that a more rigid and unimaginative language like Java doesn't have. If you have a whole bunch of basically mediocre guys working for you, consider JSP or Ruby instead of JS-only. If you are required to use PHP, just shoot yourself.
  3. You have to keep basic session state in the anchor tag. Users simply expect that the URL represents the state of the site: reload, bookmark, back, forward. jQuery's Address plug-in will do a lot of the work for you.
  4. If SEO is an issue for you, investigate Google Ajax Crawling. Basically, you make a very simple parallel site, just for search engines.

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.

知足的幸福 2024-10-16 04:18:03

模块化。
多个文件允许您更清晰地划分不同的工作流程路径和流程部分。
您的业​​务规则通常不会直接影响您的布局规则,并且多个文件可以更好地帮助编辑需要编辑的内容,而不会有破坏不相关内容的风险。

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.

坏尐絯 2024-10-16 04:18:03

实际上,我刚刚仅使用一个页面开发了我的第一个应用程序。

..它变得混乱

我的想法是创建一个尽可能模仿桌面环境的应用程序。特别是,我希望在弹出窗口中显示一些应用程序数据的详细视图,无论它们位于应用程序的哪个部分,都可以保持其状态。

因此,我的弗兰肯斯坦诞生了。

由于预算/时间限制,最终发生的事情是代码失控。我的 JavaScript 源代码的各个部分都混在一起了。事实证明,保持各种观点的正确状态是……困难的。

通过适当的规划和技术,我认为“一页”方法是一种非常简单的方法,可以打开一些非常有趣的可能性(例如:跨应用程序部分维护状态的小部件)。但它也打开了许多...许多潜在问题领域。包括...

  • 淹没全局命名空间(如果您还没有自己的... make one)
  • 代码组织很容易变得...失控
  • 上下文 - 这很容易,

我确信还有更多...

简而言之,我强烈建议您不要仅仅因为兼容性问题而依赖 JavaScript。我逐渐意识到,根本不需要依赖 JavaScript 来完成一切


我实际上正在删除 渐进增强。这更有意义。您可以使用正确编码的 JavaScript 实现相同或相似的效果。

这个想法太...

  1. 开发出格式良好、功能齐全的应用程序,无需任何 JavaScript
  2. 样式 它
  3. 用 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...

  • Flooding the global namespace (if you don't already have your own... make one)
  • Code organization can easily get... out of hand
  • Context - It's very easy to

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...

  1. Develop out well-formatted, fully functional application w/o any JavaScript
  2. Style it
  3. Wrap the whole thing with JavaScript

Using Progressive Enhancement one can develop an application that delivers the best possible experience for the user that is possible.

木緿 2024-10-16 04:18:03

对于一些其他论点,请查看《单​​页界面宣言》以及 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

她比我温柔 2024-10-16 04:18:03

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.

雨落□心尘 2024-10-16 04:18:03

在单个页面上使用 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.

放我走吧 2024-10-16 04:18:03

我完全鄙视那些不需要 JS 的网站。这个额外的条件使一切变得不同。以经常引用的 Google Docs 为例,在这种情况下,它不仅有助于改善体验,而且至关重要。但 Google 帮助的某些部分是纯 JS 的,但它没有给体验带来任何好处,它只显示静态内容。

以下是我感到不安的原因:

  • 和许多人一样,我是 NoScript 的用户并且喜欢它。页面加载速度更快,我感觉更安全,并且避免了更分散注意力的广告。最后一点对网站管理员来说似乎是一件坏事,但我不希望任何人因为在我面前推出烦人的华而不实的东西而获得奖励,如果不老练的广告商倒闭,我认为这是自然选择。
    显然,这意味着您网站的某些访问者要么会被拒绝,要么因需要提供临时排除而感到困扰。这会减少你的观众。
  • 你正在重复努力。浏览器已经具有完美的历史记录功能,您不需要通过单击后退按钮时重新绘制上一页来重新发明轮子。更糟糕的是,返回页面不需要重新渲染。我想我是 If-it-ain't-broke-dont-fix-it School 的学生(来自 Don't-Repeat-Yourself U.)。
  • JS 中遍历“页面”时没有 HTTP 标头。这意味着没有缓存控制、没有过期、无法根据请求的语言或位置调整内容、没有有意义的“找不到页面”或“不可用”响应。您可以在超级页面中编写错误处理例程来响应失败的 AJAX 获取,但这会更加复杂和重新发明,它是多余的。
  • 没有缓存对我来说没什么大不了的,没有缓存代理就无法有效工作,而缓存具有最大的减轻负载的效果。同样,您可以在 JS 应用程序中模仿一些缓存,但这会带来更多的复杂性和冗余、更高的内存使用率和更差的总体用户体验。
  • 初始加载时间更长。在第一次访问时加载大量 JavaScript 会导致更长的延迟。
  • JavaScript 的复杂性越高,意味着在各种浏览器中进行的调试就越多。服务器端处理意味着只需调试一次。
  • Unfuddle(错误跟踪器)留下了不好的印象。我最不愉快的网络经历之一是被雇主强迫使用这项服务。从表面上看,这似乎很合适;但事实上,这似乎很合适。 JS 密集部分是私有的,因此无需担心搜索引擎,只有重复访问者才会使用它,因此有时间关闭保护,并且不应该介意初始 JS 库加载。
    但它使用 JS 是没有意义的,大多数内容都是静态的。 “页面”仍在获取(通过 AJAX),因此延迟是相同的。借助 AJAX 的优势,它应该在后台轮询以检查更改,但当可见页面被修改时我不会收到通知。各个部分具有不同的样式,因此在遍历这些部分时会出现尴尬的重新渲染,通过 Javascript 加载外部样式表是糟糕的做法。为了“看看我们的 Web 2.0”功能而牺牲了易用性。这样的面向业务的应用程序应该注重检索速度,但结果却变慢了。
    最终我不得不拒绝使用它,因为它扰乱了团队的工作流程。这不利于客户与供应商的关系。
  • 动态页面更难保存以供离线使用。一些移动用户喜欢提前下载并关闭连接以节省电量和数据使用量。
  • 动态页面对于屏幕阅读器来说更难解析。虽然盲人用户的数量可能少于使用 NoScript 或移动连接的用户,但忽视无障碍功能是不可原谅的 - 在某些国家甚至是非法的,请参阅“残疾歧视法”(1999 年)和“平等法”(2010 年)。

正如其他答案中提到的,“渐进增强”,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:

  • Like many, I am a user of NoScript and love it. Pages load faster, I feel safer and the more distracting adverts are avoided. The last point may seem like a bad thing for webmasters but I don't want anyone to get rewarded for pushing annoying flashy things in my face, if tactless advertisers go out of business I consider it natural selection.
    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.
  • You are duplicating effort. The browser already has a perfectly good history function and you shouldn't need to reinvent the wheel by redrawing the previous page when a back button is clicked. To make matters worse going back a page shouldn't require re-rendering. I guess I am a student of If-it-ain't-broke-don't-fix-it School (from Don't-Repeat-Yourself U.).
  • There are no HTTP headers when traversing "pages" in JS. This means no cache controls, no expiries, content cannot be adjusted for requested language nor location, no meaningful "page not found" nor "unavailable" responses. You could write error handling routines within your uber-page that respond to failed AJAX fetches but that is more complexity and reinvention, it is redundant.
  • No caching is a big deal for me, without it proxies cannot work efficiently and caching has the greatest of all load reducing effects. Again, you could mimic some caching in your JS app but that is yet more complexity and redundancy, higher memory usage and poorer user experience overall.
  • Initial load times are greater. By loading so much Javascript on the first visit you are causing a longer delay.
  • More JavaScript complexity means more debugging in various browsers. Server-side processing means debugging only once.
  • Unfuddle (a bug-tracker) left a bad taste. One of my most unpleasant web experiences was being forced to use this service by an employer. On the surface it seems well suited; the JS-heavy section is private so doesn't need to worry about search engines, only repeat visitors will be using it so have time to turn off protections and shouldn't mind the initial JS library load.
    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.
  • Dynamic pages are harder to save for offline use. Some mobile users like to download in advance and turn off their connection to save power and data usage.
  • Dynamic pages are harder for screen readers to parse. While the number of blind users are probably less than those with NoScript or a mobile connection it is inexcusable to ignore accessibility - and in some countries even illegal, see the "Disability Discrimination Act" (1999) and "Equality Act" (2010).

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文