Full page caching for HTML pages
[1] configure a Filter on the server to cache js, css, and image.
package cn.com.system.filter;import java.io.IOException;import java.util.Enumeration;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletResponse;public class CacheForWeekFilter {private FilterConfig fc;public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {HttpServletResponse response = (HttpServletResponse) res;for (Enumeration e = fc.getInitParameterNames(); e.hasMoreElements();) {String headerName = (String) e.nextElement();response.addHeader(headerName, fc.getInitParameter(headerName));}chain.doFilter(req, response);}public void init(FilterConfig filterConfig) {this.fc = filterConfig;}public void destroy() {this.fc = null;}}
Web. xml configuration
CacheForWeek
cn.com.system.filter.CacheForWeekFilter
Cache-Control
max-age=604800, public
CacheForWeek
/js/
CacheForWeek
/images/
CacheForWeek
/css/
After this step is completed, the page cache has been implemented on the server, but the page will still be accessed every time in the current situation, but the pressure is reduced.
How can I prevent the page from accessing the server for a period of time?
The implementation method is that all common JS files are put into one page, and other pages include them, and the page cache is added to this page.
<%@ page language="java" pageEncoding="UTF-8"%>
<script src="${pageContext.request.contextPath}/common/jquery/js/jquery-1.8.2.js" charset="utf-8"></script><script src="${pageContext.request.contextPath}/common/jquery/js/jquery.ui.core.js" charset="utf-8"></script>