On Friday, 22 December 2023 at 19:55:07 UTC, Dmitry Ponyatov
wrote:
It is possible to statically precompile some JS libs and media
fragments into an app binary?
My colleagues asks me to distribute app as a single standalone
executable if it is possible, and maybe few millisecond of page
load can be saved due to serving some assets from RAM.
Sure, try enum with import expression.
https://dlang.org/spec/expression.html#import_expressions
```d
enum myEmbebbedAsset = import("somefile.jpg");
// somewhere else for example in HTTP response handler
res.write(cast(ubyte[]) myEmbeddedAsset);
```
That enum will have that asset embedded in your executable.
It is used in conjunction with -J flag (string imports paths in
dub) to tell where to find file, due to security considerations
random files from unknown location are disallowed.
Just keep in mind that enum has some quirks in some cases where
enum array access will allocate every time you access it, you can
probably avoid this by using `immutable` or just `__gshared`
variable.