问题
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 ofhtml
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