I have a task to do that I am having a hard time to do. I need to stop caching of JS files. We have a JSP based website (underdevelopment in LAN) which has some JS code too. If I try to set HTTP headers in JSP or in meta tags the JS files still return 304 status code.
Here's my code:
At the beginning of the JSP file -
<%
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
Inside head tag -
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<meta http-equiv="pragma" content="no-cache" />
<script type='text/javascript' src='./cachetest.js'></script>
I have found a way to reload the JS everytime by passing a random number or time since epoch as parameter as -
<script type='text/javascript' src='./cachetest3.js?id=<%=timeSinceEpoch>'></script>
But this seems to be a very crude way of doing it, is there something, I had a look at fiddler, the JSP or HTML entry will have the correct header and gets 200 status, but if the JS file is not changed I get 304.
What is a good way to do this?