v1.41.1 - Static Assets API in Encore.ts #1389
marcuskohlberg
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Encore.ts now comes with built-in support for serving static assets (such as images, HTML and CSS files, and JavaScript files).
This is useful when you want to serve a static website or a single-page application (SPA) that has been pre-compiled into static files.
When defining static files, the files are served directly from the Encore.ts Rust Runtime. This means that zero JavaScript code is executed to serve the files, freeing up the Node.js runtime to focus on executing business logic. This dramatically speeds up both the static file serving, as well as improving the latency of your API endpoints.⚡️
Learn more in the docs
Example app showing how to serve static files
Example
Serving static files in Encore.ts works similarly to regular API endpoints, but using the
api.static
function instead.This will serve all files in the
./assets
directory under the/frontend
path prefix.Encore automatically serves
index.html
files at the root of a directory. In the case above, that means that requesting the URL/frontend
will serve the file./assets/index.html
, and/frontend/hello
will serve the file./assets/hello
or./assets/hello/index.html
(whichever exists).Other improvements & bug fixes
Thanks to our New Contributors ❤️
Full Changelog: v1.40.0...v1.41.0
This discussion was created from the release v1.41.1 - Static Assets API in Encore.ts.
Beta Was this translation helpful? Give feedback.
All reactions