我们使用以下组件开发多语言网站:
MBCompresion - 我们使用该库的源文件来集成JS / CSS minify和compression。此外,我们编写了HttpFilter,它将页面上的所有JS / CSS组合到一个请求中(一个用于JS,一个用于CSS)。我们使用MBCompression中的FileSystemStorage作为缓存策略。
jQueryUI Datepicker - 我们按原样使用它,包含本地化文件。
jQGrid - 同样,我们按原样使用它,包含本地化文件。
所有这些都很好...... ASPX页面上的“脚本”标签被组合成单个“脚本”标签。它向jslib.axd请求HttpHandler,处理程序将所有JS文件合并到一个文件中,用GZip压缩它,将压缩文件保存在FileSystem上,然后将该文件发送到客户端。
问题:唯一的问题是网站切换到中文时。当站点使用中文时,使用GZip压缩和FileSystem缓存,到达客户端的javascript无效 - 它包含奇怪的字符和错误,如“Uncaught SyntaxError:Unexpected token ILLEGAL”。经过一些调查,我发现问题只出现在jqGrid和jQuery Datepicker的中文本地化文件中 以下是到达客户端的javascript示例(只是几行):
jQuery(function($){$.datepicker.regional['zh']={closeText:'s�',prevText:'<
Uncaught SyntaxError: Unexpected token ILLEGAL
',nextText:'>',currentText:'�)',monthNames:['','�',' ','�','�','m','','k',']','A','A','A�'],monthNamesShort:['','�',' ','�','�','m','','k',']','A','A','A�'],dayNames:['�','','�',' ','�','�','m'],dayNamesShort:['h�','h','h�','h ','h�','h�','hm'],dayNamesMin:['�','','�',' ','�','�','m'],weekHeader:'h',dateFormat:'yy-mm-dd',firstDay:1,isRTL:false,showMonthAfterYear:true,yearSuffix:'t'};$.datepicker.setDefaults($.datepicker.regional['zh']);});
当我禁用GZip压缩时,everithing工作正常。当我将缓存更改为OutputCache时,当我在中文上使用带有FileSystemCache的GZip时,everithing工作......唯一的问题。所有其他语言(甚至是日本语)都很完美。
我甚至不知道会出现什么问题。我认为它可能与Encoding有关,但我没有在FileStream上看到将压缩的JS写入文件的这些参数或属性。
请帮我解决这个问题。
感谢。
答案 0 :(得分:0)
解决!!!问题出在Utils类中的MBCompression StringToBytes方法:
/// <summary>
/// Convert string to byte[]
/// <para>Faster than the built-in method, and prevent encoding problems</para>
/// </summary>
/// <param name="stringValue"></param>
/// <returns></returns>
public static byte[] StringToBytes(string value)
{
int length = value.Length;
byte[] resultBytes = new byte[length];
for (int i = 0; i < length; i++)
{
resultBytes[i] = (byte)value[i];
}
return resultBytes;
}
我将此方法更改为:
/// <summary>
/// Convert string to byte[]
/// <para>Faster than the built-in method, and prevent encoding problems</para>
/// </summary>
/// <param name="stringValue"></param>
/// <returns></returns>
public static byte[] StringToBytes(string value)
{
Encoding Utf8 = Encoding.UTF8;
return Utf8.GetBytes(value);
}
现在看起来一切正常,包括中文。