response.writeEarlyHints(hints[, callback])
hints<Object>callback<Function>
向客户端发送 HTTP/1.1 103 Early Hints 消息,并带有 Link 头,指示用户代理可以预加载/预连接链接的资源。hints 是一个包含要随 early hints 消息发送的头值的对象。可选的 callback 参数将在响应消息写入完成后被调用。
【Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,
indicating that the user agent can preload/preconnect the linked resources.
The hints is an object containing the values of headers to be sent with
early hints message. The optional callback argument will be called when
the response message has been written.】
示例
const earlyHintsLink = '</styles.css>; rel=preload; as=style';
response.writeEarlyHints({
'link': earlyHintsLink,
});
const earlyHintsLinks = [
'</styles.css>; rel=preload; as=style',
'</scripts.js>; rel=preload; as=script',
];
response.writeEarlyHints({
'link': earlyHintsLinks,
'x-trace-id': 'id for diagnostics',
});
const earlyHintsCallback = () => console.log('early hints message sent');
response.writeEarlyHints({
'link': earlyHintsLinks,
}, earlyHintsCallback);