In the text imports proposal there was an issue about ensuring text encoding, now while the resolution of that issue was that there was no way to actually tell if the resource refers to text so the best that could be done is to add the note "String whose value should represent textual data".
However with import bytes, now it's actually possible to observe the underlying bytes. As such we should consider whether a pair of imports to the same resource should require a consistent interpretation from text and bytes imports.
i.e. Should we ever allow the following to be able to print false?:
import text from "./file.txt" with { type: "text" };
import bytes from "./file.txt" with { type: "bytes" };
console.log(text === new TextDecoder().decode(bytes));
There are tradeoffs either way:
If we don't require consistency if two modules load the same file two different ways it's possible for them to get out of sync if for example the file is modified between two fetches. (e.g. Some part of the codebase loads a config file using text imports, and another with byte imports).
If we do require consistency, then for a text import hosts will need to keep the original bytes, this might cost more memory depending on the string implementation. Also for browsers, I'm not sure if they want to send the same or different headers to the server for text vs bytes imports, then they would not only need to keep the original bytes but also need to compare the bytes to previously loaded entries.
In the text imports proposal there was an issue about ensuring text encoding, now while the resolution of that issue was that there was no way to actually tell if the resource refers to text so the best that could be done is to add the note "String whose value should represent textual data".
However with import bytes, now it's actually possible to observe the underlying bytes. As such we should consider whether a pair of imports to the same resource should require a consistent interpretation from text and bytes imports.
i.e. Should we ever allow the following to be able to print false?:
There are tradeoffs either way:
If we don't require consistency if two modules load the same file two different ways it's possible for them to get out of sync if for example the file is modified between two fetches. (e.g. Some part of the codebase loads a config file using text imports, and another with byte imports).
If we do require consistency, then for a text import hosts will need to keep the original bytes, this might cost more memory depending on the string implementation. Also for browsers, I'm not sure if they want to send the same or different headers to the server for
textvsbytesimports, then they would not only need to keep the original bytes but also need to compare the bytes to previously loaded entries.