我刚刚发现部分响应在我们的客户机器中被缓存为完整的,导致整个网站无法使用。我完全不知道,那里有什么可能出错的。Firefox存储缓存不完整响应
那么在下面的设置中可能会出错?
在服务器端,我们有一个ASP.NET应用程序在运行。一个IHttpHandler处理对JavaScript文件的请求。它基本上是在请求时缩小文件的大小,并将结果写入响应流。但是它也记录该字符串的长度被写入到Response插播:
String javascript = /* Javascript is retrieved here */;
HttpResponse response = context.Response;
response.ContentEncoding = Encoding.UTF8;
response.ContentType = "application/javascript";
HttpCachePolicy cache = response.Cache;
cache.SetCacheability(HttpCacheability.Public);
cache.SetMaxAge(TimeSpan.FromDays(300));
cache.SetETag(ETag);
cache.SetExpires(DateTime.Now.AddDays(300));
cache.SetLastModified(LastModified);
cache.SetRevalidation(HttpCacheRevalidation.None);
response.Headers.Add("Vary", "Accept-Encoding");
Log.Info("{0} characters sent", javascript.length);
response.Write(javascript);
response.Flush();
response.End();
内容然后通常使用gzip编码与传输编码分块发送。对我来说似乎很简单。
不幸的是,我刚刚和一个用户进行了远程会话,其中只有大约1/3的文件在缓存中,当然打破了文件(15k而不是44k)。在缓存中,内容编码也设置为gzip,所有通信都通过https进行。
在用户机器上打开源文件后,我只需按Ctrl-F5,即可立即显示完整内容。
什么可能会出错?
如果它的事项,请找缓存条目从下面的Firefox:
Cache entry information
key: <resource-url>
fetch count: 49
last fetched: 2015-04-28 15:31:35
last modified: 2015-04-27 15:29:13
expires: 2016-02-09 14:27:05
Data size: 15998 B
Security: This is a secure document.
security-info: (...)
request-method: GET
request-Accept-Encoding: gzip, deflate
response-head: HTTP/1.1 200 OK
Cache-Control: public, max-age=25920000
Content-Type: application/javascript; charset=utf-8
Content-Encoding: gzip
Expires: Tue, 09 Feb 2016 14:27:12 GMT
Last-Modified: Tue, 02 Jan 2001 11:00:00 GMT
Etag: W/"0"
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
Date: Wed, 15 Apr 2015 13:27:12 GMT
necko:classified: 1
更新:经过一段时间,我放弃了。缩小的js文件现在以唯一的名称写入文件系统,并由IIS直接提供。这个问题从那以后就没有发生过。 – Andreas