- From: Jimmy Wärting <notifications@github.com>
- Date: Sat, 22 Nov 2025 09:44:25 -0800
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1800/3566919452@github.com>
jimmywarting left a comment (whatwg/fetch#1800) I don't think we should even encourage ppl to use base64 when we have better containers to handle bytes. base64 takes up more RAM and size and other overhead by converting data to and from bytes -> string -> bytes > Base64 encoding typically increases the size of the original data by about 33% because it converts every 3 bytes of binary data into 4 bytes of encoded text. This overhead occurs because Base64 uses a set of 64 characters to represent the data, which requires more space than the original binary format. if the intent was to show a picture with `<img>` doing something like: ```js const response = await fetch(url); // with credentials or other METHOD other than GET const blob = await response.blob(); const reader = new FileReader(); reader.readAsDataURL(blob); await new Promise(resolve => reader.onload = resolve); const base64 = reader.result const image = new Image() img.src = base64 document.body.append(img) ``` then it has to waste process of converting bytes to base64 (only so that you can assign `img.src` with a base64 url only for browser to have to convert that `img.src` url back into bytes again. a cleaner solution would be to do: ```js const response = await fetch(url); // with credentials or other METHOD other than GET const blob = await response.blob(); const image = URL.createObjectURL(blob) img.src = base64 document.body.append(img) ``` then browser can read the bytes directly from the blob without having to do: bytes -> base64 string -> bytes --- your proposal is good, but it lacks reasoning for why we even need base64 in the first place. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/1800#issuecomment-3566919452 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/fetch/issues/1800/3566919452@github.com>
Received on Saturday, 22 November 2025 17:44:29 UTC