Type safe static assets
Referencing static assets in your web application is an error prone-process that the compiler can help type-check. Obelisk does this with the help of Nix, TemplateHaskell
and TypeApplications
.
The frontend code would look like this:
import Obelisk.Generated.Static -- Generated by Nix
elAttr "link" ("href" =: static @"main.css" <> "type" =: "text/css") blank
The static @"main.css"
is guaranteed to compile only if you have the associated file in the project directory.
To see how this works, look at the the Nix part which uses obelisk-asset-manifest to generate that module (during nix-shell
or nix-build
).