Unicode characters or encoded entities [duplicate]

别等时光非礼了梦想. 提交于 2019-12-04 06:48:45

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17609830/unicode-characters-or-encoded-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!