Reputation: 2943
I'm trying to load an html page from a jsp file. like this. I give the file name to the jsp from a controller and using dojo I call another controller and pass the file name.
<script type="text/javascript">
var url = dojo.moduleUrl("dijit.form", "<c:url value="/getfile?Name=${fileName}"/>");
dojo.xhrGet({
url: url,
load: function(html){
dojo.byId("mycontent").innerHTML = html;
}
});
It streams the file contents to the jsp. My problem is when I change the contents of the file it is not reflecting. For firefox I have to use Ctrl+f5 and for IE I've to clear the cache manually. How can I avoid this? I've given
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta HTTP-EQUIV="Expires" CONTENT="0"/>
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache"/>
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache"/>
in my the jsp files and html file.
Upvotes: 1
Views: 210
Reputation: 1108692
Two ways:
Put it in the HTTP response headers, not in the HTML head. The meta tags are only interpreted when the file is opened from local disk file system, not when the file is obtained by HTTP. A Filter
is a perfect tool for the job. Plus, you forgot two more Cache-Control
settings. Here's a complete set:
HttpServletResponse hsr = (HttpServletResponse) response;
hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
hsr.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);
Map this Filter
on the desired URL pattern matching the HTML file.
Add a timestamp to the query string so that the browser cache is fooled.
var url = dojo.moduleUrl("dijit.form", "<c:url value="/getfile?Name=${fileName}"/>&" + new Date().getTime());
Upvotes: 3