Say you are limiting the text entered into a form to 500 characters. You don't actually stop text entry on the live form but have a counter that alerts the user when they are over. The JS code needs to know that the limit is 500. Maybe the JS code trims the text on submission too.
On submit you use AJAX to do some server-side magic with the form data. It is prudent to have the server-side PHP code now trim the comment text to 500 characters regardless of whether or not the JS code did so.
This introduces a situation where you have to enter a constant into two pieces of code, which isn't great for maintenance. This is a simple example. It could be much worst.
I am thinking of two scenarios here:
JavaScript/JQuery <-> PHP
JavaScript/JQuery <-> Node.js
How do you approach cleaning this up in order to reduce the maintenance burden and reduce the potential for errors?
The server is the only reliable place to store that kind of information as anything on the client-side can be manipulated.
So I would send a settings array or configuration file as a json string to the client.