3 ms·
It was all normal JS code to handle a complicated form we have on a customer facing portal page. By moving to htmx I was able to rely on the server side to hand
by simonbarker87 2y ago
It was all normal JS code to handle a complicated form we have on a customer facing portal page. By moving to htmx I was able to rely on the server side to handle basically everything with only a small addition of code to what it was already doing.
- unsupp0rted 2y agoIsn’t that moving code around, not deleting it?
- dlisboa 2y agoMost likely that code already existed server-side and was duplicated client-side. It's what usually happens since frontend code can't enforce invariants.
- simonbarker87 2y agoNear enough exactly this
- waivek 2y agoCould you elaborate on what you mean by "frontend code can't enforce invariants" ?
- dlisboa 2y agoFrontend code can be easily bypassed or changed so you can't trust it to keep the state of your application in good condition. Nothing prevents me from picking the same username as someone else if there is no server-side code stopping it. Nothing prevents me from replying to a deleted comment if I don't check with the server. That means that any validation that you do client-side you need to repeat server-side. Any business logic that you have client-side you also need to repeat server-side.
- ghnws 2y agoI'm qurious what that code was doing that could be just moved to the backend. Usually forms have some validation for a better experience with the final validation on the server. Did you get rid of that and just show an error if the submission failed?
- simonbarker87 2y agoNear enough yes but it was a nice helpful error message with the form fully populated as they left it - as far as it looks the user it’s client side validation as the service responds with just the correct html for the form and htmx swaps out the chunk of html. Its like old school for validation back in the CodeIgniter days.
- ranger_danger 2y agoSo the 500 lines removed was literally just removing functionality in the first place (you should always validate on both sides anyway).