29

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?

Tobu
  • 24,771
  • 4
  • 91
  • 98
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207

3 Answers3

27

Nope, all it's there for is to tell the browser which character set to decode your response with.

Robadob
  • 5,319
  • 2
  • 23
  • 32
15

No, there is no disadvantage -- but you'll need to spell "utf-8" correctly.

Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48
Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • UTF-8 isn't wrong. https://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." – drhender May 18 '21 at 14:06
  • 5
    See https://stackoverflow.com/posts/17934505/revisions – Julian Reschke May 19 '21 at 15:13
  • 4
    I 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. – drhender May 20 '21 at 16:12
12

ASCII is a subset of UTF-8, so it is perfectly safe to declare the charset as utf-8 for an all-ASCII document.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770