In Realm, the routing only happens in backend. Realm backend is powered by Rust, backend analyses the URL and HTTP Method etc to figure out what rust function to call.
These rust function return a struct implementing
realm::Page trait. Page trait is
responsible for two things: conveying what Elm app is responsible for serving this page
and what data does that Elm need.
The Elm side of project is composed of “pages”. Each page is a standalone Elm app, and on page load (or page navigation), gets loaded. The Elm pages receive the data generated by backend, so they do not have to make API call on load.
Regarding bundling: Realm supports two modes, 1. single bundle, and 2. dynamic Elm.
Note: Dynamic Elm code is not yet ported to open source Realm.
In single bundle mode, all Elm files are compiled into a single js file, this mode makes first JS request larger, but subsequent API calls are smaller as we will see.
A note on dynamic loading in Elm: Elm itself doesnt support dynamic loading or modules,
to work around that in Realm, we compile A.elm to a.js, B.elm to B.js and Main.elm to
elm.js, and instead of returning a.js etc, we return “a.js minus elm.js” since elm.js is
already available to frontend. Once we get
a.js-elm.js, we combine it with elm.js to
get a.js (this reduces 20-50% download size).
In tradition approach, if one is trying to inject data in HTML, the logic of what page needs what API call/data is duplicated between the backend code and frontend code, and they can go out of sync. In Realm approach, they can never go out of sync.
rustfmtFor Some Section