galvin Posted April 28, 2009 Share Posted April 28, 2009 In deciding whether to use PHP or Javascript for a certain part of a website, I'm being told that if Javascript can do it, I should use Javascript because it doesn't tax the server my website is on. Would you agree with that statment, or is there more to it than that? I've been working with PHP for about a year now and I literally just started teaching myself Javascript a few days ago, and I'm having trouble deciding when to use PHP and when to Javascript. If anyone has any thoughts/advice on the matter, I'd be all ears. Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/ Share on other sites More sharing options...
premiso Posted April 28, 2009 Share Posted April 28, 2009 Two separate items. Javascript is client side. PHP is serverside. The problem with javascript is it can be disabled on the client. PHP code will always be executed. So you have to ask yourself, is the task you want to preform necessary? Cause if it is, then PHP is the sure fire way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/#findComment-821451 Share on other sites More sharing options...
mrMarcus Posted April 28, 2009 Share Posted April 28, 2009 thing is, if someone goes to your site with Javascript off in their web browser, your site becomes dead. people can't turn off PHP. even if you are using Javascript for form validations and such, always do the same validations with PHP as well. PHP, if written properly and efficiently, won't tax the server to any noticeable degree, so don't worry about that. Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/#findComment-821452 Share on other sites More sharing options...
Cosizzle Posted April 28, 2009 Share Posted April 28, 2009 Ya and... no - I mean lets take that thery if Javascript can do it, I should use Javascript because it doesn't tax the server my website is on Lets say you're processing a form. Use Javascript to ensure all the fields are complete, and if that passes, then post the form. The problem with this is, what if the person had Javascript turned off? So to prevent that use both. Javascript to check the form fields, then use php isset() to check on form fields as well. I guess in the end of this example, is it REALLY needed to use javascript. I think its a mixture of both, and its for you as the programmer to decide what to use and where. Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/#findComment-821455 Share on other sites More sharing options...
galvin Posted April 28, 2009 Author Share Posted April 28, 2009 I'm not saying I do (yet) , but lets say I had a website that had CRAZY traffic. I'm talking thousands of unique visitors per day. If I did a lot of things on my site with PHP that Javascript could have done, will that tax my server significantly more than if I had used Javascript instead? I guess my problem is that I don't know enough about bandwidth from traffic vs. performing PHP tasks in terms of their effect on the server. I just feel like IF there are thousands of visitors a day and for each visit the server is being accessed via PHP, logic seems to indicate that the server speed will suffer because of it. But in actuality, maybe it's just the heavy traffic ALONE that would slow the server down, and not so much PHP performing tasks for all of that traffic. Mrmarcus said PHP, if written properly and efficiently, won't tax the server to any noticeable degree, so don't worry about that. But does that rule still apply if I have a HUGE amount of traffic? I think I just talked myself into my main question. What taxes a server more, overall traffic or PHP tasks being performed? (I realize that might be a question that depends on many variables but figured I'd ask anyway ) Also, does anyone know any percentages as far as the percent of internet users with Javascript turned off? It's gotta be really low I would think. Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/#findComment-821464 Share on other sites More sharing options...
premiso Posted April 28, 2009 Share Posted April 28, 2009 But does that rule still apply if I have a HUGE amount of traffic? PHP and MySQL are made for massive amounts of Traffic. I believe that Facebook and yahoo are coded in PHP (not sure on the DB). Do not worry about the traffic. Honestly, javascript would only do a minor amount it is not worth it. PHP is extremely efficient if coded properly. Traffic tasks the server more. PHP will not as long as it is coded properly. Simple as that. To think, this page took 0.071 seconds to create and ran 21 MySQL queries. If it did not have to run those queries it would have loaded up a ton faster. You are bogging yourself down with something that is not even relevant. The traffic will be the same with or without Javascript, so will PHP executing tasks. Simple as that. Handle data where it needs to be handled. Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/#findComment-821466 Share on other sites More sharing options...
galvin Posted April 29, 2009 Author Share Posted April 29, 2009 Thanks for setting me straight. That's actually the answer I wanted to hear because I am much more comfortable with PHP. Thanks everybody!!!! Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/#findComment-821473 Share on other sites More sharing options...
Daniel0 Posted April 29, 2009 Share Posted April 29, 2009 Downloading content and parsing it takes up the majority of the time it takes to load a page. According to Yahoo, around 80% (source). Unless your code really sucks, you should focus your optimization efforts on the front end. Quote Link to comment https://forums.phpfreaks.com/topic/156038-solved-general-questionphp-vs-javascript/#findComment-821819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.