The right time for vanilla JavaScript

I was hoping to get everyone’s opinion on this certain topic. JavaScript is practically necessary in Web Development. However, I have run into the question of using JavaScript over PHP. For example, I was recently working on a website that the client wanted built on top of Wordpress, so for the majority of the development life cycle I built the pages with PHP and Wordpress’ own scripting. Everything was functioning without vanilla JavaScript (with the small exception of Bootstrap, that was my own preference). Could I have replaced DOM manipulation with JavaScript in some portions of the website? In your own experiences did you feel it necessary to incorporate JavaScript for functionality while also using PHP? Let me know your experiences and opinions.

Tools in a box. That’s what code is. Use the tool that works for the job at hand. I shouldn’t have to include experiences to justify that logic.

The JavaScript does what the PHP can not do. PHP works on the server only, and JavaScript helps to interact with the user, in the browser on the client side. JavaScript also ensures that the data received from the user is passed to the server either through reloading the page or via AJAX. PHP does not do this at all. But PHP can process the received data from JavaScript and return it to the client in the form of a piece of data that will be put in the right place of the page by JavaScript or entirely in the form of a new page.

No. @mmassie23 don’t listen to that reply. There are plenty of reasons not to use PHP, but that isn’t one of them.

Okay @fentablar to be a bit more specific what helps you determine which tool is best for a job?

@KeJSaR I appreciate the input. So most of the time you use JavaScript and PHP hand-in-hand to take specific roles. What about using PHP in Wordpress where you can use the combination of both to interact with the user (ex. displaying sidebars)?

What helps me determine the best tool for the job is based on 2 things:

  1. Understanding the tools I have
  2. Understanding the job at hand

If I have a piece of wood and I need it cut into two pieces, then I know I need the piece of wood cut into two pieces. If I look into my toolshed and see both a handsaw and a tablesaw, I consider the piece of wood to determine if it’s most feasible to cut it via the handsaw or the tablesaw. In the end, the wood will be cut, but one of those 2 tools will be more efficient for the job and that distinction is often going to be determined by the piece of wood in question.


Look, many years I used PHP with JavaScript, but now I use JavaScript only (currently TypeScript in Angular on node.js).

I think JavaScript will have great future and possibilities both on server and client side.

But if you work with WordPress you have no choice. You should prepare HTML code of sidebar, use PHP to show it on the page and use JavaScript if you want to animate it or to interact with user. In two words - PHP is for static, JavaScript is for dynamic.

1 Like

No, I think you just don’t understand me. ))

This is exactly what I want to say.