IE6调用jsonp并且gzip压缩后JavaScript不执行的解决方法

其实这篇文章应该算是“乐豆项目”中的一个小问题,但只有IE6会出现这种问题,不怎么好处理,先记录下来。

服务器header1:
HTTP/1.1 200 OK
Date: Thu, 03 Mar 2011 05:44:02 GMT
Content-Type: text/html; charset=gb2312
Transfer-Encoding: chunked
Connection: keep-alive
Server: Apache
Expires: Mon, 26 Jul 1970 05:00:00 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"
Content-Encoding: gzip

服务器header2:
HTTP/1.1 200 OK
Date: Thu, 03 Mar 2011 06:01:56 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Server: Apache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"
Content-Encoding: gzip


服务器header3:
HTTP/1.1 200 OK
Date: Thu, 03 Mar 2011 05:44:24 GMT
Content-Type: text/html; charset=gb2312
Connection: keep-alive
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.1.6
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
Expires: Mon, 26 Jul 1970 05:00:00 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-Length: 66
p3p: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"

checkLogout({"code":100,"msg":"B1C1FC9A28142AD47C5CF9F120446F97"})


解决方案1:
不启用压缩。
http://support.microsoft.com/kb/321722


解决方案2:
服务器端PHP加如下头:
header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
//header("Cache-Control: no-cache, must-revalidate"); //ie6 会出现bug Cache-Control: no-cache 后面跟no-cache jsonp 不能执行情况
//header("Pragma: no-cache");
header("Cache-Control: max-age=0, must-revalidate");
header("Content-Type: application/x-javascript; charset=gbk");//注意这个

测试发现:"Cache-Control: no-cache……" 后面第一个不是跟 no-cache就可以。

这是我们项目解决问题所用的方案。

解决方案3:
<?php
$expires = 1;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header("Content-Type: application/x-javascript;charset=GBK\n");
http://www.netroby.com/article-3863.html


解决方案4:
网上比较多的是去掉了gzip压缩.这个办法我这里不说了,关键是根据你的WEB服务器来决定怎么做了.
另外就是去掉no-store,no-cache的头.以我这边的PHP为例:
当使用了session_start()后, 就默认已输出了no-store,no-cache了.当然去掉session_start不现实..
可以通过
session_cache_limiter(false);
header('Cache-Control:max-age=0, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
session_start();
http://www.exp2up.com/2010/04/02/%E8%A7%A3%E5%86%B3ie6%E4%B8%8B%E8%B7%A8%E5%9F%9F%E8%AF%B7%E6%B1%82%E4%B8%8D%E6%89%A7%E8%A1%8C%E7%9A%84%E9%97%AE%E9%A2%98/


注:在我们的项目当中,只有线上环境开启了gzip压缩,其它环境都没有开启。所以有些文件上传到线上就会出现这样那样的问题。

除了方案2之外,其它方案转自网上,使用时请自行段定该用那种解决方案。 


因为处理了这个问题,涨工资了,呵呵……成为500wan里30%的人,挺有成就感的。
300*300
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00661 秒