在 IIS 服务器上执行 javascript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2719748/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:38:02  来源:igfitidea点击:

Execute javascript on IIS server

javascriptiisjaxer

提问by James Westgate

I have the following situation. A customer uses JavaScript with jQuery to create a complex website. We would like to use JavaScript and jQuery on the server (IIS) for the following reasons:

我有以下情况。客户使用 JavaScript 和 jQuery 创建一个复杂的网站。我们希望在服务器 (IIS) 上使用 JavaScript 和 jQuery,原因如下:

  1. Skills transfer - we would like to use JavaScript and jQuery on the server and not have to use eg VB Script. / classic asp. .Net framework/Java etc is ruled out because of this.

  2. Improved options for search/accessibility. We would like to be able to use jQuery as a templating system, but this isn't viable for search engines and users with js turned off - unless we can selectively run this code on the server.

  1. 技能转移 - 我们希望在服务器上使用 JavaScript 和 jQuery,而不必使用例如 VB 脚本。/ 经典的asp。因此,.Net 框架/Java 等被排除在外。

  2. 改进的搜索/可访问性选项。我们希望能够使用 jQuery 作为模板系统,但这对于关闭 js 的搜索引擎和用户来说是不可行的——除非我们可以有选择地在服务器上运行此代码。

There is significant investment in IIS and Windows Server, so changing that is not an option.

对 IIS 和 Windows Server 进行了大量投资,因此无法进行更改。

I know you can run jScript on IIS using windows Script host, but am unsure of the scalability and the process surrounding this. I am also unsure whether this would have access to the DOM.

我知道您可以使用 Windows 脚本主机在 IIS 上运行 jScript,但不确定可扩展性和围绕此的过程。我也不确定这是否可以访问 DOM。

Here is a diagram that hopefully explains the situation. I was wondering if anyone has done anything similar?

这是一个图表,希望能解释这种情况。我想知道是否有人做过类似的事情?

EDIT: I am not looking for critic on web architecture, I am simply wanting to know if there are any options for manipulating the DOM of a page before it is sent to the client, using javascript. Jaxeris one such product (no IIS) Thanks.

编辑:我不是在寻找关于网络架构的评论家,我只是想知道是否有任何选项可以在页面发送到客户端之前使用 javascript 操作页面的 DOM。Jaxer就是这样一种产品(没有 IIS) 谢谢。

采纳答案by David Murdoch

Have a look at bringing the browser to the server, Rhino, and Use Microsoft's IIS as a Java servlet engine.

看看将浏览器带到服务器Rhino使用 Microsoft 的 IIS 作为 Java servlet 引擎

The first link is from John Resig's (jQuery's creator) blog.

第一个链接来自 John Resig(jQuery 的创建者)的博客。

Update August 2 2011

2011 年 8 月 2 日更新

Node.js is coming to Windows.

Node.js 即将登陆 Windows。

回答by newtover

The idea to reuse client JS on the server may sound tempting, but I am not sure that jQuery itself would be ready to run in server environment.

在服务器上重用客户端 JS 的想法可能听起来很诱人,但我不确定 jQuery 本身是否已准备好在服务器环境中运行。

You will need to define global context for jQuery somehow by initializing window, document, self, location, etc.. I am not sure it is doable.

您将需要通过初始化window, document, self, location, etc.. 我不确定它是否可行。

Besides, as Cheeso has mentioned, Active Server Pages is a very outdated technology, it was replaced with ASP.Net by Microsoft in the beginning of the century. I used to maintain a legacy system using ASP 3.0 for more than a year and that was pain. The most wonderful pastime was debugging: you will hardly find anything for the purpose today and will have to decript beautiful errors like in IIS log:

此外,正如 Cheeso 所说,Active Server Pages 是一项非常过时的技术,在本世纪初被微软用 ASP.Net 取代。我曾经使用 ASP 3.0 维护遗留系统一年多,这很痛苦。最美妙的消遣是调试:今天你几乎找不到任何用于此目的的东西,并且必须描述像 IIS 日志中的漂亮错误:

error '800a9c68'
Application-defined or object-defined error

错误 '800a9c68'
应用程序定义或对象定义错误

Nevertheless, I can confirm that I managed to reuse client and server JScript. But this was code written by me who knew that it was going to be used on the server.

尽管如此,我可以确认我成功地重用了客户端和服务器 JScript。但这是我编写的代码,我知道它将在服务器上使用。

P.S. I would not recommend move that way. There are plenty templating frameworks which are familiar to those who write HTML and JavaScript.

PS我不建议那样移动。编写 HTML 和 JavaScript 的人熟悉的模板框架很多。

回答by Weston C

I think the only viable solutions you're likely to find anywhere near ready to go involve putting IIS in front of Java. There are two browser-like environments I'm aware of coded for Java:

我认为您可能会找到的唯一可行的解​​决方案是将 IIS 置于 Java 之前。我知道有两种类似浏览器的环境是为 Java 编码的:

1) Env-js (see http://groups.google.com/group/envjsand http://github.com/thatcher/env-js) I believe this one has contributions from jQuery's John Resig and was put together with jQuery testing/support in mind.

1)Env-js(参见http://groups.google.com/group/envjshttp://github.com/thatcher/env-js)我相信这个有来自 jQuery 的 John Resig 的贡献,并与jQuery 测试/支持。

2) HTMLUnit (see http://htmlunit.sourceforge.net/) This one's older, and wasn't originally conceived around jQuery, but there are reports in the wild of using it to run jQuery's test suite successfully (http://daniel.gredler.net/2007/08/08/htmlunit-taming-jquery/).

2) HTMLUnit(参见http://htmlunit.sourceforge.net/)这个较旧,最初并不是围绕 jQuery 构思的,但是有大量报告使用它来成功运行 jQuery 的测试套件(http:// daniel.gredler.net/2007/08/08/htmlunit-taming-jquery/)。

If you want something pure-IIS/MS, I think your observation about windowsScript host and/or something like the semi-abandoned JScript.NET is probably about as close as you're going to come, along with a port (which you'll probably have to start) of something like Env-js or HTMLUnit.

如果您想要纯 IIS/MS,我认为您对 windowsScript 主机和/或诸如半废弃 JScript.NET 之类的东西的观察可能与您将要来的一样接近,以及一个端口(您可能必须开始)诸如 Env-js 或 HTMLUnit 之类的东西。

Also, I don't know if you've seen the Wikipedia list of server-side JavaScript solutions:

另外,不知道大家有没有看过维基百科的服务器端JavaScript解决方案列表:

http://en.wikipedia.org/wiki/Server-side_JavaScript

http://en.wikipedia.org/wiki/Server-side_JavaScript

Finally... you could probably write a serviceable jQuery-like library in any language that already has some kind of DOM library and first-class functions (or, failing that an evalfacility). See, for example pQuery for Perl (http://metacpan.org/pod/pQuery). This would get you the benefits of the jQuery style of manipulating documents. Skill transfer is great and JavaScript has a wonderful confluence of very nice features, but on the other hand, having developers who care enough to learn multiple languages is also great, and js isn't the only nice language out there.

最后……您可能可以使用任何已经具有某种 DOM 库和一流函数(或者,如果没有该eval功能)的语言编写一个可服务的类 jQuery 库。例如,参见 Perl 的 pQuery ( http://metacpan.org/pod/pQuery)。这将使您受益于 jQuery 风格的文档操作。技能转移很棒,而且 JavaScript 将非常好的功能完美地融合在一起,但另一方面,拥有足够关心学习多种语言的开发人员也很棒,而且 js 并不是唯一的好语言。

回答by Cheeso

JScript runs on IIS via something called ASP.
Active Server Pages.
It was first available in 1996.

JScript 通过称为 ASP 的东西在 IIS 上运行。
活动服务器页面。
它于 1996 年首次上市。

Eventually ASP.NET was introduced as a successor. But ASP is still supported.

最终 ASP.NET 作为继任者被引入。但是仍然支持 ASP。

There is no DOM for the HTML page, though.

但是,HTML 页面没有 DOM。

You might need to reconsider your architecture a bit.

您可能需要重新考虑一下您的架构。

回答by roryf

What exactly do you mean by

你到底是什么意思

"A customer uses JavaScript with jQuery to create a complex website"

“客户使用 JavaScript 和 jQuery 创建一个复杂的网站”

Half the point of jQuery is to make it easy for the developer to manipulate the DOM, and therefore add interactive enhancements to a web site. By running the Javascript on the server and only rendering HTML you will lose the ability to add these enhancements, without doing a round trip to the server (think WebForms postback model...ugh).

jQuery 的一半在于使开发人员可以轻松地操作 DOM,从而为网站添加交互式增强功能。通过在服务器上运行 Javascript 并仅呈现 HTML,您将无法添加这些增强功能,而无需往返服务器(想想 WebForms 回发模型……呃)。

Now if what you really mean is the customer uses a site builder based on jQuery, why not have that tool output flat HTML in the first place?

现在,如果您真正的意思是客户使用基于 jQuery 的站点构建器,为什么不首先让该工具输出平面 HTML?

回答by pengtuck

I think it's mainly a browser based script so probably you are better of using technologies based on VB or .NET to perform or generate HTML from templates. I'm sure there are because in the java world there are a few of these around (like velocity). You'd then use jQuery to create or add client side functionality and usability so it makes the website more usable than it would have been.

我认为它主要是基于浏览器的脚本,因此您可能最好使用基于 VB 或 .NET 的技术来执行或从模板生成 HTML。我敢肯定有,因为在 Java 世界中有一些这样的东西(比如速度)。然后,您将使用 jQuery 来创建或添加客户端功能和可用性,从而使网站比以往更易于使用。

回答by Carlos

Take a look at this technology. You can invoke scripts to run at server, at client, or both. Plus, this really implements the firefox engine on the server. Take a look at it.

看看这个技术。您可以调用脚本在服务器、客户端或两者上运行。另外,这确实在服务器上实现了火狐引擎。看一看。

Aptana's Jaxer is the first AJAX web server so far. I have not tryed it yet, but I will. Looks promising and very powerful.

Aptana 的 Jaxer 是迄今为止第一个 AJAX Web 服务器。我还没有尝试过,但我会的。看起来很有前途,而且非常强大。