digitalmars.D.learn - [vibe] statically precompile some JS libs into an app binary
- Dmitry Ponyatov (5/5) Dec 22 2023 It is possible to statically precompile some JS libs and media
- evilrat (17/22) Dec 24 2023 Sure, try enum with import expression.
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.
Dec 22 2023
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.
Dec 24 2023