Bytes Encoders and Decoders

elm-pages does use the Lamdera compiler to get some automatic Bytes Encoders and Decoders that it uses to communicate between the frontend and backend apps.

~

How does elm-pages work? page Connect 2 Apps

[…] it's all just Elm, plus some code generation, and generating two Elm applications. One backend version that runs at build-time, or on each server-request if it's a server-rendered route. And one frontend version that takes the initial HTML and data provided by the backend app.

elm-pages does not change Elm's pure functions. In fact, it heavily relies on this as a basis for its design! It does give you BackendTask which allows you to execute data. It may not seem like it, but this is nothing more than a plain old Elm Custom Type!

That Custom Type is handled with some special behavior by the framework to give you a lot of functionality, but it doesn't in any way break the guarantees you know and love from any other Elm application.

Think of BackendTask like a Cmd or Effect. It's a special type which you pass up to the runtime to ask it to do something for you. Since Elm code is pure, it can't perform side-effects. BackendTasks will not do anything unless they're passed to the elm-pages framework. Since the framework has its own Model, update, etc., it's able to go perform side-effects to resolve those BackendTasks for you. You can think of it like a wrapper around The Elm Architecture site .

~

Cannot Get View ⇒ Bytes Encoders and Decoders ⇒ BackendTask

Eric Dobbs via matrix (2021) I wonder if the underlying mechanism in v8 that makes their deploy of data urls work is the same thing that makes this line work in my ESM Snippet Template.

let module = await import(`data:text/javascript;base64,${btoa(text)}`)

Data URLs mdn