Is there a default charset for data URIs? I read the spec but I don't see one.
For instance, if I have a data URI for a source map which I expect to be reliably interpreted across browsers, is it OK to omit the charset?
//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJza...
vs
//@ sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJza...
I see in this GitHub issue that people have had problems using Chinese characters in source-mapped files without an explicit charset=utf-8
. So if there is a default (or, at least, if we could expect browsers to have chosen one), it doesn't seem like utf-8
is the one...
According to RFC 2397 § 2, a data URI without a specified charset
defaults to US-ASCII
. Because every Base64-encoded URI uses only ASCII characters. Moreover, “all US‑ASCII strings become valid UTF‑8” which means there’s “decent backwards compatibility in many cases”.1
Nevertheless, UTF-8 implementation remains uneven in 2019. Because of that – and because there is little cost to explicitly calling the charset
to already-user-unfriendly data URIs – it’s probably not a bad idea to include charset=utf-8
in your sourcemap URIs in order to keep them reliably interpreted across browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With