Jump to content
j.silver

Importance of JS

Recommended Posts

Hi all,

 

Why do we hear and read that js is one of three programming languages a web programmer must learn besides html and css when there are also other widely used server-side languages, such as PHP? Is it because browsers are designed to mainly understand html, css, and js? If there are other reasons, kindly them spell out?

Share this post


Link to post
Share on other sites

Javascript is not a server-side language. It is the only client-side scripting language, so it is necessary to add behaviors to the page.

Share this post


Link to post
Share on other sites

Server-side languages generally require a page reload to do something. Javascript is client-side code and runs in the client browser and can do things quickly without reloading the page or bothering the server. Javascript code can also minimize the server workload by only requesting the portion of the page that needs to be updated rather than reloading an entire new page.

Share this post


Link to post
Share on other sites

Are you asking in the context of PHP7 vs NodeJS? Otherwise, you are comparing apples and oranges.

Share this post


Link to post
Share on other sites

I'm not familiar with Node JS. What I am trying to get at is that if there is a block of code written in PHP7, and the same block is written in JS. If both are made to run on the same server, which technology executes such code and outputs result faster?

Share this post


Link to post
Share on other sites

Server-side Javascript is done with node.js. Obviously it's not going to be the same code, they're 2 different languages, but some basic testing is possible.

 

Node is generally faster than vanilla PHP, but using something like HHVM makes PHP a lot faster and more efficient. Although the PHP core developers would tell you that HHVM isn't necessary and they have in fact made a lot of progress in the performance area.

 

Here's a set of benchmarks for PHP 5 versus node:

 

http://www.hostingadvice.com/blog/comparing-node-js-vs-php-performance/

 

While those numbers don't look very good for vanilla PHP, keep in mind also that PHP 7 has much better performance than PHP 5. You can find benchmarks comparing those two as well to see that PHP 7 can be about 30-40% faster for some of the basic tests, but I can't find a ton of benchmarks for PHP 7 versus node.

 

Note also that this has nothing to do with Javascript running in a browser. It's not very meaningful to compare client-side Javascript with server-side languages, they do completely different things.

Share this post


Link to post
Share on other sites

I'm not familiar with Node JS. What I am trying to get at is that if there is a block of code written in PHP7, and the same block is written in JS. If both are made to run on the same server, which technology executes such code and outputs result faster?

 

Do you understand the concept of a client-server architecture? NodeJS is a special implementation of Javascript that runs on the server -- but NORMALLY Javascript only runs on the client.

Share this post


Link to post
Share on other sites

It depends on what the code actually does! If reading content from db, then you are restricted to PHP that requires page reload everytime, or a bit both PHP and JavaScript used in a AJAX request, but this relies on JavaScript being enabled in first place. JavaScript content is not read by search bots either, so what you will have listed is blank content to search through. Form validation need to always have server-script validation, with JavaScript validation as enhancement to make it quicker, without drawback of reloading page each time with PHP to identify errors in input.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...