From 9176fa5bad6cf44704c16b53966dfbd98d9988d2 Mon Sep 17 00:00:00 2001 From: Mark Ladyshau <47859603+mrkldshv@users.noreply.github.com> Date: Sat, 2 Jul 2022 17:50:19 +0200 Subject: [PATCH] docs: garbage collection `HEAD` method note (#1522) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index c2639bb7633..432eb265932 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,13 @@ const headers = await fetch(url) .then(res => res.headers) ``` +However, if you want to get only headers, it might be better to use `HEAD` request method. Usage of this method will obviate the need for consumption or cancelling of the response body. See [MDN - HTTP - HTTP request methods - HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) for more details. + +```js +const headers = await fetch(url, { method: 'HEAD' }) + .then(res => res.headers) +``` + ##### Forbidden and Safelisted Header Names * https://fetch.spec.whatwg.org/#cors-safelisted-response-header-name