# Frontend principles Applies to a project with a browser frontend. General principles (KISS, DRY, …) live in `technical-principles.md` and apply here too. ## Foundational stances | Principle | Explanation | |-----------|-------------| | Backend-agnostic | Tight coupling between front- and backend causes duplicated work. **Why?** The front- and/or backend should be replaceable independently of each other, to allow us to improve and/or modernize incrementally. | | Prefer state in the URL first, backend second | State can be managed in the backend, in the URL, and in the browser (e.g. JavaScript memory, local storage, etc). We want to limit state management in the browser as much as possible and focus on the backend and the URL. **Why?** Working with state in the browser is difficult from a development perspective. It is not intuitive that the same URL yields different results on different devices or even different tabs. Centralized state can be shared across multiple separate frontends. | | Prefer backend-based business logic | Centralized logic can be consumed by multiple separate frontends and minimizes duplication. **Why?** To avoid distributing logic and risking that different rules apply to the same thing, depending on where in the system it is done. | | CSS > JavaScript | If something can be solved with CSS, solve it with CSS. If you can negotiate with product to achieve the same functionality in a way that can be solved with CSS instead of JavaScript, solve it with CSS. **Why?** CSS is significantly more performant than JS. CSS is declarative in contrast to JS, which makes it much more robust against bugs and issues. | | Prefer established web standards over custom solutions | For example, use an HTML select instead of a cool library that renders a similar-looking select out of divs and CSS. HTML and CSS are managed by a committee that thinks long and hard before anything changes. Things are deprecated for years before they stop working, if they ever do. **Why?** Standards will always outlive the week's hottest framework and give us a more stable foundation to build on. Upgrading an entire framework is usually significantly more cumbersome than upgrading a single library. Frameworks push us toward doing what they want us to do rather than what we want to do ourselves. | | Use semantic HTML | Use HTML elements for their meaning (`