On Dec 1, 2011, at 12:49 PM, Nate Hill wrote:
> As I was struggling with the syntax trying to figure out how to use
> javascript to load a .txt file, process it and then spit out some html on a
> web page, I suddenly found myself asking why I was trying to do it with
> javascript rather than PHP.
>
> Is there a right/wrong or better/worse approach for doing something like
> that? Why would I want to choose one approach rather then the other?
>
> As always, apologies if I'm asking a terribly basic question.
There's different advantages to each side:
JavaScript / JScript / ECMAScript / client side:
Scales better (as the clients do their own work)
More obnoxious to maintain (as different browsers may have slightly different implementations)
Less reliable (I keep mine turned off on my main browser)
Better detection of client features (you can always lie in a browser string, or just not send it)
May require extra layers of abstraction (APIs that then require extra taint checking)
More responsive for simple operations (if doesn't need remote calls)
Easier to do some tasks
PHP / ColdFusion / CGI / ASP / server side :
You can be assured that you know it's working, and error reports when it's not (assuming you log & check your logs)
the inverse of all of the ones in the 'client side' section
(but the inverse of 'Easier to do some things' is till 'Easier to do some things')
I'm not going to make any claims about speed, as it's frequently dependent
on bandwidth/latency. (if I can send data to the client on a slow link, and
have them build the structures around it, it might be faster than my doing
it server side, and more so if my server gets bogged down)
For some tasks, I'll do it both ways. Eg, form input validation --
Once in javascript, so they get the warning *before* the submit the form,
and again on the server side, in case they have javascript off or are being
malicious.
-Joe
|