Execute javascript on IIS server
Asked Answered
T

7

7

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:

  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.

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

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.

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. Jaxer is one such product (no IIS) Thanks.

Tem answered 27/4, 2010 at 8:29 Comment(7)
Related question: #1992322Chandless
@Chandless - thanks - I did see that question but it doesnt really answer how JScript can manipulate the DOM before the markup is sent to the browser. The way I understand it, JScript can only be used to generate markup in that scenario.Tem
Maybe you could explain WHY you want to run jQuery on the server. jQuery is primarily used in making browser apps more dynamic and responsive and less dependent on the page/request model. What is the source of the desire to use that sort of library on the server? The HTML DOM is not accessible on the server, but if it were, there would be no dynamic effects visible. You would just get a modified DOM. Why not produce the content on the server-side as desired in the first place, rather than hoping to produce it, and then modify it with jQuery?Radbourne
Thank you. I understand why and how jQuery is used on the client. As I explained in my question, sometimes this is not feasible. 1 - for search engine reasons 2. for some accessibility scenarios when script is disabled. I would simply like to shift this processing to the server in either of these two scenarios without having to split my code. I am not interested in dynamic effects, I am interested in DOM manipulation.Tem
@James Westgate. I just want to say that I love this idea. Someone should port Rhino to C#. [drool]Dotterel
This looks promising javascriptdotnet.codeplex.comTem
So this has come to be known as Isomorphic javascript. Question asked way before the term was coined, although the world is moving on from jQuery now of course. :)Tem
D
6

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

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

Update August 2 2011

Node.js is coming to Windows.

Dotterel answered 3/5, 2010 at 18:4 Comment(2)
Thank you very much, this is exactly what I was looking for. Although it may not be great from a performance viewpoint, its a start. I definitely think there is an opportunity for a .net javascript server side implementation based on the DLR combined with John Resigs ideas. I may start a project on git/codeplex.Tem
sweet. keep us informed. I'm definitely interested.Dotterel
S
2

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.

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

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:

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

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.

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

Stumble answered 27/4, 2010 at 12:3 Comment(1)
Thanks. Im very familiar with these technologies. I can see a definite benefit in being able to execute jQuery on the DOM before it is sent to the browser.Tem
R
1

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

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

There is no DOM for the HTML page, though.

You might need to reconsider your architecture a bit.

Radbourne answered 27/4, 2010 at 8:43 Comment(2)
Thanks. I understand asp, asp.net et al. I want to apply the same javascript programming model on the server as I do on the client. So its a case of trying to make the technology fit the ideal architecture.Tem
The reason I pointed out that JScript runs in ASP, is because of your statement, I know you can run jScript on IIS using windows Script host, but.... That statement didn't mention the primary technology that would be used to run JScript on IIS.Radbourne
M
1

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:

1) Env-js (see http://groups.google.com/group/envjs and 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.

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

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.

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

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 eval facility). 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.

Marcelline answered 3/5, 2010 at 18:38 Comment(1)
One more thing I forgot to add: if you don't find an answer you're satisfied with here, you might try the Common JS Google Group (groups.google.com/group/commonjs ). I think you're likely to hear mostly what I've told you here, but if you search the group for IIS, there's at least one discussion where people have briefly mentioned they were considering windows script host and IIS.Marcelline
H
0

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.

Hurtful answered 27/4, 2010 at 8:34 Comment(1)
Thanks for the answer. I'm trying to see if it is possible to use the client programming model that the css and photoshop centric developers are used to - to a server environment based on IIS.Tem
U
0

What exactly do you mean by

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

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

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?

Unison answered 27/4, 2010 at 9:9 Comment(2)
Thanks. I understand jQuery's uses very well. Its a large manufacturer's website as opposed to an intranet/extranet business application, so the logic is based more around templating and animation.Tem
Thanks again for the response. Would you believe that it is flat html with tonnes of jQuery. And that is duplicated with xsl and xml transforms on the server for <noscript> versions.Tem
M
0

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.

Moniz answered 7/4, 2011 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.