Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why do many web developers use server-side scripting languages like PHP when everything they e trying to do can be done with JavaScript?

0
Posted

Why do many web developers use server-side scripting languages like PHP when everything they
e trying to do can be done with JavaScript?

0

Where the best place is to perform a given operation (client javascript vs. server side PHP) depends a ton on the type of operation so there is no generic answer to that question. Some reasons to perform things client-side: • Better performance (faster responsiveness to user events, fewer server-roundtrips, more logic handled client-side, etc…) • Lower load on your servers • Faster visual feedback • Dynamic page performance without page reloads • Interactive application Some reasons to perform things server-side: • Better performance (bigger computers, faster internet pipe, faster connection to data sources, etc…) • Faster access to server-side data • Better management of bandwidth to client • Easier to secure and control access to data server-side than client-side • Fewer cross -browser issues • Smaller pages for browser to download • Same server logic can be exposed via XML or a JSON-type API As you can see there are tradeoffs in both directions so where the ideal place is to put

0

Everything could be done with Javascript if you use Node.js server side. You can use the same code on the server and client in cases like form validation. You can generate HTML on the server in cases where the client doesn’t have javascript enabled, uses IE6, is a bot etc. For most visitors you can send lighter JSON and render the views client side, with minor modifications to code you use to render HTML server side. Many of these features are early in the development cycle so they’re buggy. In a few years many PHP/Ruby shops may jump on the server side Javascript train, attracted by server/client code compatibility. Servers and PHP are still used for features that can be handled client side with HTML5, like image editing, word count, spell check etc. It takes time to change development practices. Many HTML5 features became widely available only this year and IE still hasn’t added them. There is also a cultural perception that JavaScript is incapable and annoying, and the real web is s

0
10

I don’t think it’s true that everything like that can be done in JavaScript. The most obvious counter-example for this is storing data on the server (be it text in the database or an image/file on the server’s HDD). As far as I know JS/HTML5 only allows for local (client-side) storage (and not even in all browsers) and even if you can upload a file to the server (via normal HTTP request) that’s where the JS hits the barrier – it can’t be executed on the server and manipulate/store the file in a specific place on the server. There are also a lot of other disadvantages of relying only on JavaScript. A lot of them have been mentioned in other answers (security (for example performing encryption in js is probably a big no-no), ability to turn off js completely by the client, ability to read the code by the client, inconsistencies between browser implementation of specific js classes and more). One thing I could add is that building DOM structure entirely via JavaScript kills off any SEO. G

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.