0

I'm using some special characters like × (×) or … (…) in my html pages.

Somewhere I'm using unicode character directly, but somewhere I'm using encoded entity like &hellip.

I want to tidy up my code and can't decide what notation is better.

I could find just two pros and cons:

  • using character directly I can set text in javascript using text method like $("#button").text("Loading…"), instead of html which could lead to XSS issues
  • using characters directly can lead to encoding issues in case of misconfigured server

Maybe I'm missing something important? What is the best practice?

Community
  • 1
  • 1
Gregory Kalabin
  • 1,760
  • 1
  • 19
  • 45
  • 1
    To put it simply: who enjoys wörking with HTML éntities whén it's müch easier to work with the actual characters? – deceze Jul 12 '13 at 07:47
  • The topic is covered in many existing questions (not perfectly, but it is more productive to improve existing answers than to spawn new discussions). It is largely opinion-based and context-dependent, and the question is posed as problem of tidying up code – something that you shouldn’t be doing in the first place. – Jukka K. Korpela Jul 12 '13 at 09:48
  • 1
    Note that if you need to get `text()` working in an ASCII-only environment you should use JavaScript string literal escapes: `"Loading\u2026"`. But yeah, unencoded characters are usually best, except in cases where they might prove confusing (eg ` `). – bobince Jul 12 '13 at 09:53

1 Answers1

2

If you use Unicode directly there's a chance that someone saves the file with the incorrect encoding and all characters get mangled.

On the other hand, using entity codes means you can't search effectively in the source code; you have to remember how each non ASCII character is encoded. Same goes for database content. Readability suffers,too.

I prefer to use Unicode directly and everyone on the team knows that files must be encoded in UTF-8.

Joni
  • 108,737
  • 14
  • 143
  • 193