j.silver Posted November 19, 2016 Share Posted November 19, 2016 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? Link to comment Share on other sites More sharing options...
Ingolme Posted November 19, 2016 Share Posted November 19, 2016 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. Link to comment Share on other sites More sharing options...
davej Posted November 19, 2016 Share Posted November 19, 2016 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. Link to comment Share on other sites More sharing options...
j.silver Posted November 22, 2016 Author Share Posted November 22, 2016 Any idea how loading speed of js (and speed in general) compares with the speed of PHP7? Link to comment Share on other sites More sharing options...
thescientist Posted November 22, 2016 Share Posted November 22, 2016 Are you asking in the context of PHP7 vs NodeJS? Otherwise, you are comparing apples and oranges. Link to comment Share on other sites More sharing options...
j.silver Posted November 22, 2016 Author Share Posted November 22, 2016 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? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 22, 2016 Share Posted November 22, 2016 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. Link to comment Share on other sites More sharing options...
davej Posted November 22, 2016 Share Posted November 22, 2016 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. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 23, 2016 Share Posted November 23, 2016 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now