docs: update canary docs for Fresh 2 (#3108)

There are still some rough edges here and there, but it's in a much
better shape than what we have today.
This commit is contained in:
Marvin Hagemeister
2025-07-18 15:18:38 +02:00
committed by GitHub
parent a66e0df08d
commit a703e79181
29 changed files with 2094 additions and 62 deletions
+47
View File
@@ -0,0 +1,47 @@
---
description: |
Fresh has built-in support for serving static files. This is useful for serving images, CSS, and other static assets.
---
Static assets placed in the `static/` directory are served at the root of the
webserver via the `staticFiles()` middleware. They are streamed directly from
disk for optimal performance with
[`ETag`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag)
headers.
```ts
import { staticFiles } from "fresh";
const app = new App()
.use(staticFiles());
```
## Caching headers
By default, Fresh adds caching headers for the `src` and `srcset` attributes on
`<img>` and `<source>` tags.
```jsx
// Caching headers will be automatically added
<img src="/user.png" />;
```
You can always opt out of this behaviour per tag, by adding the
`data-fresh-disable-lock` attribute.
```jsx
// Opt-out of automatic caching headers
<img src="/user.png" data-fresh-disable-lock />;
```
## Adding caching headers manually
Use the `asset()` function to add caching headers manually. It will be served
with a cache lifetime of one year.
```jsx
import { asset } from "fresh/runtime";
// Adding caching headers manually
<a href={asset("/brochure.pdf")}>View brochure</a>;
```