Ask HN: JavaScript in server-rendered webapps
How do you structure the JS code in server rendered webapps? How do you structure pjax code? I'm wondering also if there's an open source project I can take a look at.
- URL routing on both client/server: for navigation without page reload, as well as rendering the same content when the user lands on a particular page for the first time (or refreshes the page)
- Templates on both client/server: maybe you could share the same HTML (or Mustache, Pug, etc.) templates on both sides
- Passing initial state from server -> client: typically, a JS snippet can be injected in a page template to pass an object, so the client-side can sync the state (initial route, etc.)
- Dynamic loading of additional scripts: some routes may request additional scripts via AJAX/fetch, in which case a small library/wrapper may be useful, to know when it finished loading to do something