Is there any disadvantage of using: text/plain; charset="UTF-8"
32,754
Solution 1
Nope, all it's there for is to tell the browser which character set to decode your response with.
Solution 2
No, there is no disadvantage -- but you'll need to spell "utf-8"
correctly.
Solution 3
ASCII is a subset of UTF-8, so it is perfectly safe to declare the charset
as utf-8
for an all-ASCII document.
Related videos on Youtube
Author by
Jeroen Ooms
#rstats developer and staff RSE for @ropensci at UC Berkeley.
Updated on April 13, 2021Comments
-
Jeroen Ooms about 3 years
My web server serves content that is in 95% of the time just simple ascii. However in some rare cases, the content contains some German non-ascii characters.
Now I could set the
content-type
response header by detecting if the content contains any non-ascii characters, or I could just always set the response header:Content-Type: text/plain; charset=UTF-8
Is there any disadvantage in doing the latter?
-
drhender almost 3 yearsUTF-8 isn't wrong. datatracker.ietf.org/doc/html/rfc7231#section-3.1.1 section 3.1.1.1 (Media Type) includes: > the following examples are all equivalent, but the first is preferred for consistency: text/html;charset=utf-8, text/html;charset=UTF-8, Text/HTML;Charset="utf-8", text/html; charset="utf-8" section 3.1.1.2 (Charset) states: "A charset is identified by a case-insensitive token."
-
Julian Reschke almost 3 years
-
drhender almost 3 yearsI see- the OP originally used "UTF8", which is incorrect. That definitely adds context as to why you needed to correct the spelling. I hope my note at least adds some value about what now appears to be a comment about just case differences.