HTML頁面實現全方位頁面緩衝,頁面全方位

來源:互聯網
上載者:User

HTML頁面實現全方位頁面緩衝,頁面全方位

【1】服務端配置一個Filter,實現對js、css和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配置

<filter>          <filter-name>CacheForWeek</filter-name>          <filter-class>cn.com.system.filter.CacheForWeekFilter</filter-class>          <init-param>              <param-name>Cache-Control</param-name>              <param-value>max-age=604800, public</param-value>          </init-param>      </filter>     <filter-mapping>          <filter-name>CacheForWeek</filter-name>          <url-pattern>/js/</url-pattern>      </filter-mapping>      <filter-mapping>          <filter-name>CacheForWeek</filter-name>          <url-pattern>/images/</url-pattern>      </filter-mapping>      <filter-mapping>          <filter-name>CacheForWeek</filter-name>          <url-pattern>/css/</url-pattern>      </filter-mapping> 
完成這一步,在服務端已經實現了對頁面的緩衝,但是當前情況下頁面還是會每次訪問伺服器的,只是壓力減小了

如何讓頁面在一段時間內不訪問伺服器呢

實現方式是對應公用的JS都放到一個頁面中,別的頁麵包含他,在這個頁面中增加頁面緩衝

<%@ page language="java" pageEncoding="UTF-8"%><meta charset="utf-8" /><span style="color:#ff0000;"><meta http-equiv="cache-control" content="max-age=604800, public"></span><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><!--IE10--><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><!--<meta name=”renderer” content=”webkit|ie-comp|ie-stand”>--><meta name=”renderer” content=”webkit|ie-comp|ie-stand” /><!-- CSS styles --><link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/base.css" /><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>




什是網站緩衝?就是產生html頁面?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.