解決https無法緩存的問題


火狐棄用http,轉而大力推廣https的動作一石激起千層浪,非常多沒有安裝安全證書的站點使用新版火狐瀏覽器已經打不開了。

之前我們站點僅僅有涉及須要加密的部分連接為https協議。眼下看來不得不將整個站點的連接均加裝https。原本執行正常的功能就這樣出現了問題。具體情況是,產品列表頁面使用ajax載入產品的時候不能再像從前那樣緩存之前載入好的數據了。造成這樣的情況的原因主要有兩點,第一點是在后台設置的過濾器強制每一個頁面不緩存內容。第二個原因便是由於整個站點都進行了安全加密,使得瀏覽器本身不會再進行頁面緩存。解決問題的方法是在須要緩存數據的頁面設置強制緩存,例如以下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();

	int nMinutes = 60 * 24 * 7;
	Date d = new Date();
	String modDate = d.toGMTString();
	String expDate = null;
	expDate = (new Date(d.getTime() + nMinutes * 60000)).toGMTString();
	response.setHeader("Last-Modified", modDate); 
	response.setHeader("Expires", expDate); 
	
	response.setHeader("Pragma","public");
	response.setHeader("Cache-Control","public");	
%>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link href="<%=path%>/resources/weixin/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path%>/resources/weixin/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="<%=path%>/resources/weixin/js/progressbar.js"></script>
<script type="text/javascript" src="<%=path%>/resources/weixin/js/common.js"></script>
<script type="text/javascript" src="<%=path%>/resources/weixin/js/account.js"></script>
<script type="text/javascript" src="<%=path%>/resources/js/common.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#investpage").addClass("current");
	if(isWeiXin()){
		$("#page").val("1");
	}
 	addMoreProducts();
});
</script>
<title>普惠理財-產品列表</title>
</head>
<body>
	<header id="header">
		<h3>產品列表</h3>
	</header>
	<div id="container">
		<form id="centerForm" name="centerForm" method="post" action="">
			<input type="hidden" id="page" name="page" value="1" />
		</form>
		<div id="proList" class="pro_list">
			
			
		</div>
		<div id="addTag " class="addTag">
			<a href="javascript:void(0)" onclick="addMoreProducts()">
				<span id="loading" class="icon"></span><span id="promtText">載入中...</span>
			</a>
		</div>
	</div>
	<footer id="footer">
		<jsp:include page="../footer.jsp" />
	</footer>
</body>
</html>

尤其要注意Cache-Control的值和Pragma的值均為”public“。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM