Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of server side javascript over java

I'm new to server side javascript programming, and I'm trying to understand the differences between this and the traditional server side java. What are the significant differences and why is SSJS becoming popular? How is SSJS better than Java? From a layman's perspective, I would assume JS to be slower than Java in terms of performance, primarily because of it being an interpreted language.

Regards, Anand

like image 308
Anand Avatar asked May 13 '12 09:05

Anand


People also ask

What is an advantage of using server side JavaScript?

A server-side rendering benefit is the reduced dependency on JavaScript frameworks, resulting in a reduced page weight. Furthermore, JavaScript files can significantly add to the overall page weight. It's not uncommon for a suite of JavaScript libraries to be over 1 MB in size.

What is one advantage to using JavaScript over server-side scripting languages?

JavaScript Advantages Speed − JavaScript is a "interpreted" language, it cuts down on the time needed for compilation in other programming languages like Java. Another client-side script is JavaScript, which accelerates programme execution by eliminating the wait time for server connections.

What is the advantage of server-side?

Some server-side rendering advantages include: A server-side rendered application enables pages to load faster, improving the user experience. When rendering server-side, search engines can easily index and crawl content because the content can be rendered before the page is loaded, which is ideal for SEO.


3 Answers

I think node.js has had a lot to do with the rise of this phenomenon:

http://nodejs.org/

Pretty sure it has been the impetus for a lot of the commonjs library development, etc.

I see comments to the effect that it makes lives easier when the client and server side code is in the same language. For the node project I worked on, there were only 3 programmers for everything initially, and we were more-or-less given carte blanche to use whatever technology we wanted. This led to some debate as everybody had different backgrounds; but when somebody suggested nodejs, one reason it seemed like a good idea was that javascript was something we all had in common.

However, I don't think the success of node is mainly because it uses js; it's about the design. I liked it a lot more than most of the other server side technology I've worked with (Rails, PHP, cgi, mod_perl, mason), and I would probably have liked it just as much regardless of the language used in the interface. But js it is.

So that's my point: I think it has less to do with anything in particular about javascript and more to do with some of the clever thinking and development that has gone on in the "javascript community", surprise surprise. Consider PHP: I don't think the success of PHP had much to do with the design (or performance characteristics) of the language, I think it had to do with the nature of how it is used and how people conceived of server side programming 10-15 years ago, and (closely related) the tools they had to build upon.

One issue there (in the "clever thinking" department) is the (very convincing-if-you-try-it) assertion made by the people behind node and, eg, nginx, to the effect that an asynchronous, event driven model is better suited to server programming than the traditional parallel synchronous, thread driven model. I believe the later predominates in java, even tho methinks it could just as easily be used the other way. Javascript, on the other hand, was originally intended for use in the asynchronous, event driven world of the browser, and doesn't have threads at all. Again: not so much the language, but the culture.

Also worth noting is the predominant use of JSON as an interchange format and of NoSQL databases like couchdb (which I've used) and mongodb (which I haven't), that make fundamental use of JSON in structuring the db. Couchdb also uses js for some server side programming (basically, query handlers), presumably because the database documents are in JSON, which is also nice to hand off to the client. Very slick and clever. One language, one protocol, from model to view; in a significant sense, there is no "interchange" at all.

like image 185
CodeClown42 Avatar answered Sep 26 '22 02:09

CodeClown42


the differences between this and the traditional server side java

First of all, Java and JavaScript have nothing in common. They are two totally different things. Keep that in mind.

  • I think many people like server side JavaScript, because they can stay in one language. They use JavaScript on the server as well on the client, instead of using another language (like Java, PHP or Ruby). Also, a lot of web programmers are familiar with JavaScript (because they use it on the client), so they understand it well.

  • JavaScript can also be easier as Java. If you have just a small project, Java could be a lot of overhead compared to JavaScript. Some things like callbacks could be very elegant in JavaScript.

  • Also, new frameworks like Node.js make it attractive to use this language. As long as there wasn't any server side framework, you simple couldn't use JavaScript on the server. But the language has evolved well today.

  • I think the performance of JavaScript depends also on the server. I'm not sure of this, but as far as I know, JavaScript could be (just in time) compiled, too. Google's chrome is doing something like that. Also, performance isn't such a big thing on most websites, because the performance is mostly IO to a database. The actual creation of an HTML page is very simple and no big thing. And: PHP is also interpreted and used on many sites. Ruby is significant slower then Java, but Ruby on Rails is very popular. So performance seems not so important. It's more about how "nice" and elegant the language is.

like image 20
Thomas Uhrig Avatar answered Sep 25 '22 02:09

Thomas Uhrig


The main advantage from my point of view is simplification of client-server interaction if you have rich JS client interface. If you use the same language at server and client side you can share common code between them (for example, if you have some business logic like validation and it is used at client and at server you can implement it once in JS and use in several places).

And if you already know JS you should not learn a new language to do server-side work.

like image 20
dbf Avatar answered Sep 24 '22 02:09

dbf