Expires

用于向 HTTP 响应添加 Expires 标头的中间件

配置参数

defaultDuration number

The default duration for unknown types

Default:
604800000
durations record

List of types with the cache duration

Default:
{
  "text/html": 0,
  "application/json": 0,
  "application/xml": 0,
  "application/atom+xml": 3600000,
  "application/rdf+xml": 3600000,
  "application/rss+xml": 3600000
}

Description

这是一个中间件,用于在响应中包含 Expires 标头,以获得更好的缓存效果。

Installation

这个中间件必须与 Lume 的 HTTP 服务器 一起使用。要在生产环境中使用它,你需要一个运行 Deno 服务器的主机,例如 Deno Deploy

创建一个入口点文件(例如,serve.ts),包含以下代码:

import Server from "lume/core/server.ts";
import expires from "lume/middlewares/expires.ts";

const server = new Server();

server.use(expires());

server.start();

Local development

不建议在本地开发中使用此中间件,因为本地服务器的重点是不缓存资源并确保提供最新版本。