What’s your take on this dilemma?
I’ve been diving deep into JavaScript lately and it’s been amazing. But I’m noticing that I’m swapping out simple server-side tasks (using PHP) with small JavaScript snippets. Take this example - instead of using server logic to highlight which menu item is active based on the current page, I’m doing it with client-side code:
var currentPath = document.location.href;
if (currentPath.includes("/services/")) {
document.querySelector(".menu-services").classList.add("active");
}
This approach feels clean and quick, but I worry about depending too much on JavaScript. Do others handle similar scenarios this way? How do you manage and organize this type of code? Where do you draw the line between reliable server-side processing that always works versus smooth client-side interactions that might fail if users disable JavaScript?
UPDATE
I’m not just talking about this specific case - I mean small improvements like this in general. What criteria do you use to decide between JavaScript enhancements versus server-side implementation?