我有一個關於GZip的奇怪問題,我希望你能幫助我。爲什麼我在使用GZip縮小JS和CSS時會丟失數據?
using (MemoryStream memoryStream = new MemoryStream(10240))
{
//isCompressed will be true if the browser accepts gzip
using (Stream writer = isCompressed ?
(Stream)(new GZipStream(memoryStream, CompressionMode.Compress)) :
memoryStream)
{
StringBuilder sb = new StringBuilder();
//filenames is collection of multi js files need to be minify
foreach (string fileName in fileNames)
{
sb.Append(File.ReadAllText(context.Server.MapPath(fileName)));
}
//minifier is an instance of Microsoft.Ajax.Utilities.Minifier
string minifiedString = minifier.MinifyJavaScript(sb.ToString());
byte[] bts = Encoding.UTF8.GetBytes(minifiedString);
writer.Write(bts, 0, bts.Length);
}
}
BTS的長度其實是6000,但是,當writer.Write(bts, 0, bts.length)
已執行,作家只能寫2334個字,我查了內部信息,它說,操作不支持,我對此感到十分困惑,我不知道爲什麼?
打開IIS中的靜態和動態壓縮並不總是一個選項。例如,如果他在共享主機上,某些託管公司會在共享計劃上禁用它。爲此減少我仍然使用我的自定義庫進行壓縮/縮小。 –
好點。你知道任何受歡迎的託管服務提供商不允許IIS壓縮嗎? –
如果託管服務提供商不允許您打開gzip,則更改託管提供商是我的觀點... –