103 Early Hints
Lets the server send some headers (like links to CSS or JS) before the main response is ready, so the browser can start preloading resources in advance.
When and Why to Use It
Section titled “When and Why to Use It”Use this to optimize load times. While your server is busy gathering data for the main response, you can fire off a 103 Early Hints to tell the browser ‘Start downloading these CSS & JS files while you wait for my actual response’.
Usage Examples
Section titled “Usage Examples”import { HttpCode, get } from 'shokupan';
export const getResource = get('/resource', () => { return { message: 'Early Hints' };}).pipe(HttpCode(103));import { Controller, Get, HttpCode } from 'shokupan';
@Controller('/api')export class ExampleController { @Get('/resource') @HttpCode(103) getResource() { return { message: 'Early Hints' }; }}import express from 'express';const app = express();
app.get('/resource', (req, res) => { res.status(103).json({ message: 'Early Hints' });});import { Controller, Get, HttpCode } from '@nestjs/common';
@Controller('api')export class ExampleController { @Get('resource') @HttpCode(103) getResource() { return { message: 'Early Hints' }; }}import Koa from 'koa';const app = new Koa();
app.use(async ctx => { if (ctx.path === '/resource' && ctx.method === 'GET') { ctx.status = 103; ctx.body = { message: 'Early Hints' }; }});