My SPA application is built using Websocket, Polymer, ES6, and HTML5. It is hosted on a Jetty 9 backend bundled as a runnable JAR with all resources inside.
I want to implement a feature where upon deploying a new version of the JAR, I can send a message to the client instructing it to perform a cache-less refresh of all resources.
To serve my SPA, I have a custom HttpServlet
that handles URL "rewriting":
private static final Path ROOT = getDevelopmentWebRoot();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestPath = req.getPathInfo();
if (requestPath.equals("/")) {
requestPath = "index.html";
} else {
requestPath = requestPath.substring(1);
}
Path resource = ROOT.resolve(requestPath);
resp.setHeader("Cache-Control", "max-age=31536000");
resp.setContentType(MimeTypes.getDefaultMimeByExtension(resource.toString()));
try {
Files.copy(resource, resp.getOutputStream());
} catch (NoSuchFileException e) {
Files.copy(ROOT.resolve("index.html"), resp.getOutputStream());
}
}
My main query is, how can I trigger a cache-less refresh using JavaScript?