jcfrei
jcfrei

Reputation: 1809

Concatenating javascript files with different encodings

Is there a general/best practice approach on how to deal with multiple encodings? since the js code on my site is about the same for every page, putting everything into one file makes sense, however I've run into a lot of wierd issues since some files are UTF-8, some ASCII, some have CLRF and some RF endings.

EDIT So far I've used cat, however as far as I'm aware cat keeps the original encoding in place.

Upvotes: 0

Views: 130

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336188

You should definitely aim for a unified encoding across all your files; if UTF-8 files are among them, then UTF-8 is the way to go. ASCII isn't a problem here (ASCII is a subset of UTF-8, so you can concatenate UTF-8 and ASCII files without problems), but other encodings (latin-1 etc.) are. You definitely want to avoid mixed encodings within a single file.

You should also normalize your line endings (all CRLF or all LF, but not both; certainly not within a single file - that's just ugly). On Unix systems, LF is the standard, so that's probably what you should be using.

cat doesn't care about encodings at all, it just pastes the files together, so it will mess up if you concatenate files with different encodings/line endings.

Upvotes: 2

Related Questions