Best Cache Practice
- Use Gulp, Webpack, or similar to add unique hash digits to css, js, and image files (like app-67ce7f3483.css);
- For js,css, and image files, set "Cache-Control: public, max-age=31536000", no Etag, no Last-Modified settings.
- For html files and API response, use "Cache-Control: no-cache" and Etag.
Protocols
h2 (HTTP2)
使用 TCP。多路复用。
h3 (HTTP3)
使用基于 UDP 的 QUIC。强制要求使用 TLS 1.3。
The QUIC transport protocol used by HTTP/3 requires all connections to be secured using TLS 1.3. This means that when you configure domains to offer HTTP/3, you are also configuring them to offer TLS 1.3 to clients using HTTP/1.1 or HTTP/2.
默认必须先建立 HTTP/1.1 或 H2 会话,然后服务器通过 Alt-Svc HTTP 响应 header 支持客户端切换(Upgrade)到 H3 协议。
DNS 的 HTTPS record 允许指示客户端在初始链接就自动使用 H3。
代理软件和协议目前对 QUIC 支持不佳。直接在 Windows 系统或 Chrome 里配置 HTTP / Sock5 代理都会导致 Chrome 自动禁用 h3 ?。
Static HTTP Server
Go 写的静态 HTTP 服务器
- static-file-server (Dockerhub: halverneus/static-file-server)
- 文件较小。但只支持使用 ENV 配置,例如: HOST / PORT / FOLDER
docker run -d -v /datadir:/web -p 8080:8080 halverneus/static-file-server:latest
- simplehttpserver (Dockerhub: projectdiscovery/simplehttpserver)
- 文件稍大。但支持命令行参数配置。
Headers
Cache
禁止任何 cache :
cache-control: no-store
expires: 0
注意以上并不能阻止 service worker 提供的 cache。
CORS
允许任何 CORS 请求:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: *
Cross-Origin-Resource-Policy: cross-origin