I can request an html page with Fetch API, but I just need the title, is it possible to request partial html page (the beginning) ?
Asked
Active
Viewed 395 times
2
-
1You could consume the fetched html as a stream and abort the fetch once you have what you need. – Sebastian Speitel Jan 20 '21 at 18:34
-
Isn't it better using DOMParser? – AbsoluteBeginner Jan 20 '21 at 19:32
-
DOMParser is AFTER so too late ;) – user310291 Jan 21 '21 at 00:07
1 Answers
2
The title of a page exists in the HTML markup. For this page, it's:
<head>
<title>javascript - Fetch API : is it possible to request partial html page (the beginning) - Stack Overflow</title>
So you will need to at least make an initial request for the whole page response.
If you want to try to stop parsing the response as soon as the first chunk (which will likely contain the <title>
) comes in, you could use a readable stream and close and/or use an AbortController
.

CertainPerformance
- 356,069
- 52
- 309
- 320