You just described how the whole web operates. It works just fine.
Even if you want client side, we have better ways now than cookies.
We do, but only cookies are universally available. Plenty of unusual user-agents in the world, or people like me that browse with JS off by default.