简体   繁体   English

用不同的编码连接javascript文件

[英]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. 因为我的网站上的js代码对于每个页面大致相同,所以将所有内容放在一个文件中是有道理的,但是我遇到了很多奇怪的问题,因为有些文件是UTF-8,有些是ASCII,有些是CLRF,有些是射频结束。

EDIT So far I've used cat, however as far as I'm aware cat keeps the original encoding in place. 编辑到目前为止,我已经使用过cat,但据我所知,cat保留了原始编码。

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. 如果UTF-8文件是其中之一,则UTF-8是可行的方法。 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. ASCII不是问题(ASCII是UTF-8的子集,因此您可以毫无问题地连接UTF-8和ASCII文件),但其他编码(latin-1等)是。 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). 你还应该规范你的行结尾(所有CRLF或所有LF,但不是两者;当然不是在一个文件中 - 这只是丑陋)。 On Unix systems, LF is the standard, so that's probably what you should be using. 在Unix系统上,LF是标准,所以这可能就是你应该使用的。

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. cat根本不关心编码,它只是将文件粘贴在一起,所以如果你用不同的编码/行结尾连接文件会很麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM