Take the 2-minute tour ×

I'm beginning to learn javascript and I wrote an infinite loop

    document.write("hello world");

I ran top -d .5 from the commandline and didn't see this script take up CPU.

I then created an infinite loop in .php

        echo "Hello World";

I ran top -d .5 from the commandline and saw this .php script take up CPU.

This leads me to believe that when an infinite loop written in javascript runs, it only taxes your computer's resources, not the server's (I guess that's why they call it a client-side language.) Can someone confirm this?

And more generally, does this mean that all the interpreting of javascript taxes only your computer's resources, not the server's?

share|improve this question
JavaScript is just a language. There're several implementations, including server-side ones like Node.js –  Álvaro G. Vicario Jan 30 '12 at 8:23
add comment

3 Answers

up vote 5 down vote accepted

True and true. When making a loop in PHP wich is server-side you will take up resources from your server. When doing scripting in "javascript" you will use the clients resources, unless you of course do serverside calls. In most modern browsers Javascript just uses the browsers memory wich means that you cannot take up all computer resources before your browser will quit on you.

Best regards Jonas

share|improve this answer
+1 best imho best answer cause it points out making calls inside the loop. –  Filburt Jan 30 '12 at 8:38
Thank your for the +1 and edit Filburt. Have a wonderfull day. Best regards Jonas –  Jonas m Jan 30 '12 at 9:00
add comment

You are absolutely correct.

Javascript runs client-side.

share|improve this answer
that's a bit too general... javascript can run on the server-side too (like node.js). –  Yahia Jan 30 '12 at 8:20
@Yahia agreed, I was looking for another question that had this topic covered to close. This was just a head's up for the user. The question, IMHO is too broad and obvious for SO. –  Frankie Jan 30 '12 at 8:22
@Yahia I'm voting you up because I could not find a similar question... –  Frankie Jan 30 '12 at 8:25
thanks for the update of my answer :-) –  Yahia Jan 30 '12 at 8:37
add comment

Anything that runs consumes resources where it is running.

In your samples:

  • client javascript: takes only resources of the client (it doesn't access any other machine)
  • php: the php takes resources of your server

You should also be aware that javascript can run on the server, node.js is a good example of server-side javascript.

share|improve this answer
add comment

Your Answer


