浏览器刷新破坏捆绑的javascript

时间:2016-02-05 14:10:55

标签: javascript asp.net google-chrome iis

我将ASP.NET javascript捆绑和minfication添加到我们的网站,并发现现在如果我刷新网站,捆绑的javascript文件将被下载为gzip但从未被浏览器解压缩,因此该网站当然不会工作,因为javascript仍然是压缩的。如果我再次刷新,该网站是好的。再次刷新,腐败。来来回回。这仅发生在Chrome和Safari中,但不会发生在IE中。

在Fiddler中观看,IE第一次获取javascript,后续刷新返回304未修改,这是正确的。 Chrome / Safari刷新每次刷新时不断返回200。

如果我在IIS Express中本地托管我的网站,则不会发生此问题。它仅在我们的其他QA,登台和制作环境中,其中网站由IIS 7.5托管。

我对好的Chrome请求和糟糕的Chrome请求进行了Fiddler比较,看看有什么不同。它们是相同的,除了坏请求具有“If-Modified-Since”标题。

当“If-Modified-Since”标题存在时,来自服务器的响应有一个Content-Type为“application / javascript”,这就是我认为导致问题的原因,浏览器不知道它应该解压缩响应主体。

这是GOOD请求和响应(为简洁起见省略了主体):

GET https://wwwq.website.com/Scripts/main.js?v=z3QOtK2bjf3mvSQyLf2KY82lAidw4JR0ePo01WHF93U1 HTTP/1.1
Host: www.website.com
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36
DNT: 1
Referer: https://www.website.com/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: < cookies omitted >

HTTP/1.1 200 OK
Date: Fri, 05 Feb 2016 13:46:30 GMT
Server: Microsoft-IIS/7.5
Cache-Control: public
Content-Type: text/javascript; charset=utf-8
Expires: Sat, 04 Feb 2017 13:46:31 GMT
Last-Modified: Fri, 05 Feb 2016 13:46:31 GMT
Vary: User-Agent,Accept-Encoding
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Via: 1.1 wwwq.website.com (Access Gateway-ag-2772908347919084-467794)
Keep-Alive: timeout=300, max=99
Connection: Keep-Alive
Content-Length: 62702

这是BAD请求和响应(为简洁省略了主体):

GET https://www.website.com/Scripts/main.js?v=z3QOtK2bjf3mvSQyLf2KY82lAidw4JR0ePo01WHF93U1 HTTP/1.1
Host: www.website.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36
DNT: 1
Referer: https://www.website.com/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: < cookies omitted >
If-Modified-Since: Fri, 05 Feb 2016 13:46:31 GMT


HTTP/1.1 200 OK
Date: Fri, 05 Feb 2016 13:46:43 GMT
Server: Microsoft-IIS/7.5
Cache-Control: private
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Vary: Accept-Encoding
Via: 1.1 www.website.com (Access Gateway-ag-2772908347919084-467849)
Content-Length: 16042
Keep-Alive: timeout=300, max=94
Connection: Keep-Alive
Content-Type: application/javascript

如果有人能帮助我,我会非常感激我的想法已经用完了。

0 个答案:

没有答案