# @eggjs/static

> static server plugin for egg

Latest version **4.1.0** (published 2026-10-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @eggjs/static
pnpm add @eggjs/static
yarn add @eggjs/static
bun add @eggjs/static
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-10-07 |
| First published | 2025-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22.18.0 |
| Dependencies | 4 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | dead_horse |
| Maintainers | gxkl, eggjs-admin, fengmk2, atian25, hyj1991, killagu, coolme200, akitasummer, elrrrrrrr, niania |
| Keywords | egg, egg-plugin, eggPlugin, static |

## Links

- npm: https://www.npmjs.com/package/@eggjs/static
- Repository: https://github.com/eggjs/egg
- Homepage: https://github.com/eggjs/egg/tree/next/plugins/static
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/@eggjs/static

## Dependencies (4)

- [ylru](https://npm.io/package/ylru.md) ^2.0.0
- [koa-range](https://npm.io/package/koa-range.md) ^0.3.0
- [koa-compose](https://npm.io/package/koa-compose.md) ^4.1.0
- [@eggjs/koa-static-cache](https://npm.io/package/@eggjs/koa-static-cache.md) 7.1.0

## Recent versions

- 4.1.0 (latest) — 2026-10-07
- 4.0.2-rc.1 (rc) — 2026-10-06
- 4.0.2-beta.27 (beta) — 2026-09-20
- 4.0.2 — 2026-10-06
- 4.0.2-rc.0 — 2026-09-23
- 4.0.2-beta.26 — 2026-08-07
- 4.0.2-beta.25 — 2026-07-13
- 4.0.2-beta.24 — 2026-07-12
- 4.0.2-beta.23 — 2026-07-11
- 4.0.2-beta.22 — 2026-07-11
- 4.0.2-beta.20 — 2026-07-09
- 4.0.2-beta.19 — 2026-06-29
- 4.0.2-beta.17 — 2026-06-28
- 4.0.2-beta.16 — 2026-06-26
- 4.0.2-beta.15 — 2026-06-26
- … 39 more at https://npm.io/package/@eggjs/static/versions

## README

# @eggjs/static

[![NPM version][npm-image]][npm-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/static.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/@eggjs/static.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/static
[snyk-image]: https://snyk.io/test/npm/@eggjs/static/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/static
[download-image]: https://img.shields.io/npm/dm/@eggjs/static.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/static

Static server plugin for egg, base on [@eggjs/koa-static-cache](https://github.com/eggjs/egg/tree/next/packages/koa-static-cache).

## Install

`@eggjs/static` is a plugin that has been built-in for egg. It is enabled by default.

## Configuration

`@eggjs/static` support all configurations in [@eggjs/koa-static-cache](https://github.com/eggjs/egg/tree/next/packages/koa-static-cache).
And with default configurations below:

- prefix: `'/public/'`
- dir: `path.join(appInfo.baseDir, 'app/public')`
- dynamic: `true`
- preload: `false`
- maxAge: `31536000` in prod env, `0` in other envs
- buffer: `true` in prod env, `false` in other envs

`@eggjs/static` provides one more option:

- maxFiles: the maximum value of cache items, only effective when dynamic is true, default is `1000`.

**All static files in `$baseDir/app/public` can be visited with prefix `/public`, and all the files are lazy loaded.**

- In non-production environment, assets won't be cached, your modification can take effect immediately.
- In production environment, `@eggjs/static` will cache the assets after visited, you need to restart the process to update the assets.
- Dir default is `$baseDir/app/public` but you can also define **multiple directory** by use `dir: [dir1, dir2, ...]` or `dir: [dir1, { prefix: '/static2', dir: dir2 }]`, static server will use all these directories.

```ts
// {app_root}/config/config.default.ts
export default {
  static: {
    // maxAge: 31536000,
  },
};
```

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).

---
_Source: https://npm.io/package/@eggjs/static · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
