构建基于纯 JavaScript 的 Web 应用程序(客户端和服务器端)有意义吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4931645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does it make sense to build pure JavaScript based web applications (both client and server side)?
提问by András Szepesházi
I've always considered JavaScript as a great addition (or rather, for the last couple of years, as a must have) to the client side of any web application. Even when I started to use Mootools, which takes a big step away from DOM manipulation, and aims toward a general purpose, OO framework, I still didn't think that I would consider using JavaScript for server-side development. JavaScript belongs to the front, period - that's what I thought.
我一直认为 JavaScript 是对任何 Web 应用程序客户端的一个很好的补充(或者更确切地说,在过去的几年里,这是必须的)。甚至当我开始使用 Mootools 时,它比 DOM 操作迈出了一大步,目标是通用的 OO 框架,我仍然没有想到我会考虑使用 JavaScript 进行服务器端开发。JavaScript 属于前沿,句号——这就是我的想法。
Well, it seems like according to some damn smart people, I was wrong. For the first time ever, the web development platform contest called Plat_Form accepted a team that used pure JavaScript bothon the server and the client side. What's more, here is what the contest organizers had to say about this:
好吧,在一些该死的聪明人看来,我错了。有史以来第一次,名为 Plat_Form 的 Web 开发平台竞赛接受了一个在服务器端和客户端都使用纯 JavaScript 的团队。更重要的是,以下是比赛组织者对此的看法:
"We had a single application of a team, Upstream Agile, that will work with JavaScript on both the server and the client side. Since this might become a major trend in coming years, we consider their participation a glimpse of the future and accept this team even though no others with this platform have applied."
"我们有一个团队的单一应用程序 Upstream Agile,它将在服务器端和客户端使用 JavaScript。由于这可能成为未来几年的主要趋势,我们认为他们的参与是对未来的一瞥并接受这一点团队即使没有其他人申请这个平台。”
So my question is: is this really a viable concept, to build multi-tier web applications purely on JavaScript? If so, what would be the advantages of using JavaScript for both the front- and the backend?
所以我的问题是:纯粹基于 JavaScript 构建多层 Web 应用程序真的是一个可行的概念吗?如果是这样,前端和后端都使用 JavaScript 有什么好处?
EDIT:The link in Vanwaril's answer (Why node.js is totally awesome) reveals an interesting discussion in the comments section that worth reading through. I, for one, have decided that though using Javascript on the server side is a viable concept and might have its benefits, I would definitely not start building an enterprise application with that architecture. At least for now. This question might need to be asked again in a year, I can imagine that the answer will dramatically change in the near future.
编辑:Vanwaril 的回答中的链接(Why node.js isfully awesome)在评论部分揭示了一个有趣的讨论,值得一读。一方面,我已经决定虽然在服务器端使用 Javascript 是一个可行的概念并且可能有它的好处,但我绝对不会开始使用该架构构建企业应用程序。最起码到现在。这个问题可能需要一年后再问,我可以想象在不久的将来答案会发生巨大的变化。
采纳答案by Vanwaril
First off, have you taken a look at node.js? JavaScript is one of the languages that, over the last few years, has seen leaps and bounds of development, and its likely to keep growing.
首先,你看过node.js吗?JavaScript 是在过去几年中发展突飞猛进的语言之一,并且可能会继续增长。
In terms of functionality, it is less mature when compared to other server-side technology, but the active community is making it not far behind.
在功能方面,与其他服务器端技术相比,它不太成熟,但活跃的社区让它不甘落后。
Finally, since its a language that runs on both the front and back-end, its implications for code-reuse and data-exchange formats make application development a whole lot faster.
最后,由于它是一种在前端和后端运行的语言,它对代码重用和数据交换格式的影响使应用程序开发速度大大加快。
I'm not sure its quite ready for production yet (unless you yourself are willing to contribute to the code-base) but server-side JavaScript is a good option to experiment with.
我不确定它是否已经准备好投入生产(除非你自己愿意为代码库做出贡献),但服务器端 JavaScript 是一个很好的试验选择。
回答by cweiske
回答by Dan Dascalescu
To actually answer the question - yes, it is perfectly viable to build client-server web applications entirely in JavaScript, and frameworks that got traction in the intervening two years since the question was asked -- notably Meteor-- make this much easier than it used to be:
要真正回答这个问题 - 是的,完全用 JavaScript 构建客户端 - 服务器 Web 应用程序是完全可行的,并且在提出问题后的两年间受到关注的框架 - 特别是Meteor- 使这比它容易得多以前是:
One Language. Write both the client and the server parts of your interface in JavaScript.
一种语言。用 JavaScript 编写界面的客户端和服务器部分。
回答by oberhamsi
We are building our CMS & frontends using http://Helma.at, currently serving ~ 250 mio pages / month. This is JavaScript through & through.
我们正在使用http://Helma.at构建我们的 CMS 和前端,目前服务约 250 mio 页/月。这是 JavaScript 贯穿始终。
Note that this is not bleeding edge technology, as you seem to assume: Helma is in development since 1998 and we use it in production since 1999.
请注意,这并不是最前沿的技术,正如您似乎假设的那样:Helma 自 1998 年以来一直在开发中,我们自 1999 年以来在生产中使用它。
回答by Quentin
So my question is: is this really a viable concept, to build multi-tier web applications purely on JavaScript?
所以我的问题是:纯粹基于 JavaScript 构建多层 Web 应用程序真的是一个可行的概念吗?
Yes, although the tools are relatively immature when compared to many other languages.
是的,尽管与许多其他语言相比,这些工具相对不成熟。
If so, what would be the advantages of using JavaScript for both the front- and the backend?
如果是这样,前端和后端都使用 JavaScript 有什么好处?
- No switching between languages for developers
- Code reuse (e.g. Want to check that data is sane? The same code can be used on the client and the server).
- 开发人员无需在语言之间切换
- 代码重用(例如,要检查数据是否正常?可以在客户端和服务器上使用相同的代码)。
回答by Danny Stevens
Server side code has to be particularly robust and well engineered, as it manages more than one client in a multi threaded environment. The complexity of business tier processes and the need for accurate code re-use has always lead me to write server side code in Java. I would not consider using Java script because it is aimed at a different usage.
服务器端代码必须特别健壮和精心设计,因为它在多线程环境中管理多个客户端。业务层流程的复杂性以及对准确代码重用的需求一直促使我用 Java 编写服务器端代码。我不会考虑使用 Java 脚本,因为它针对不同的用途。
That being said I do use Java script at the server for replicating client side validation scripts for example. That way you can use the one piece of validation code at both ends. The user gets responsive browser validation but the back end re-validates in case someone bypasses the front end validation.
话虽如此,我确实在服务器上使用 Java 脚本来复制客户端验证脚本。这样你就可以在两端使用一段验证代码。用户获得响应式浏览器验证,但后端会重新验证,以防有人绕过前端验证。
回答by Anthony
This is not a new idea. In fact its so old to have been in fashion then gone out and is now coming back again.
这不是一个新的想法。事实上,它太古老了,曾经流行过然后消失了,现在又回来了。
Clasic ASP on windows server IIS can use javascript as the server side scripting language. it can talk to local filesystem and SQL sever etc. very very simple stuff.
Windows Server IIS 上的 Clasic ASP 可以使用 javascript 作为服务器端脚本语言。它可以与本地文件系统和 SQL 服务器等通信。非常非常简单的东西。
You could easily write some ASP code that returns JSON to be consumed by your client side script ajax.
您可以轻松编写一些 ASP 代码,返回 JSON 以供您的客户端脚本 ajax 使用。
The problem is that MS have ignored classic asp and moved to asp.net (c# or VB.net) so we have to wait for the community to re-invent server side javascript to get back to where we where in 2001.
问题是 MS 已经忽略了经典的 asp 并转移到了 asp.net(c# 或 VB.net),所以我们必须等待社区重新发明服务器端 javascript 才能回到 2001 年的位置。

