en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

added fetch get example for non-utf8 pages

Open ProjectEli opened this issue 3 years ago • 5 comments

Still, some webpages do not follow standard UTF-8 encoding. As far as I know, fetch() does not support encoding options by default. Therefore, I added an example with error handling part (not already shown).

ProjectEli avatar Mar 09 '22 01:03 ProjectEli

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 09 '22 01:03 CLAassistant

Are there many pages in non-UTF in Korean (or Chinese)?

Is it a common way of using fetch, then?

iliakan avatar Apr 14 '22 03:04 iliakan

Are there many pages in non-UTF in Korean (or Chinese)?

Yes. At least there are many Korean and Japanese websites that are not in UTF8, especially for some government websites. For Chinese, I don't have much experience. In practice, many people struggle with encodings when accessing those websites programatically.

Ideally, the owners of those websites should follow international standards. However, in most cases they don't want to change, or just give up management. From the user point of view, we want to deal with what's inside rather than the charset encoding. Therefore, this example will be meaningful for beginners to utilize without a deeper understanding on non-UTF8 encodings.

Is it a common way of using fetch, then?

I agree that this is not the intended usage of fetch. But we cannot decode those websites correctly through given methods in the document. In my opinion, it is worth including as a tutorial for practical use unless we find a better way of decoding.

ProjectEli avatar Apr 14 '22 11:04 ProjectEli

So, for non-UTF Korean websites, when people use fetch, do they use it exactly as you say?

How did they cope before TextDecoder, I wonder? Did they use XMLHttpRequest?

iliakan avatar Apr 14 '22 15:04 iliakan

up )

iliakan avatar May 03 '22 19:05 iliakan