Tomcat with Gzip and cache

Source: Internet
Author: User

Original address: http://benx.iteye.com/blog/561998

The method of configuring Gzip in Tomcat is to modify the previous configuration in the Conf/server.xml file to

Java code
  1. <connector
  2. port= "8080" maxhttpheadersize="8192 "
  3. maxthreads= "minsparethreads=" "maxsparethreads= "
  4. enablelookups="false" redirectport="8443" acceptcount="
  5. connectiontimeout="20000" disableuploadtimeout="true"
  6. compression="on"
  7. compressionminsize="2048"
  8. nocompressionuseragents="Gozilla, Traviata"
  9. Compressablemimetype="Text/html,text/xml,text/javascript,text/css,text/plain"/>
  10. />

Tested before the compression of the size of 1.5M after compression only 10K, may be and have a lot of duplication of data about, response speed also has the previous 2.5 seconds to 275ms

Configured header file you'll find that out.

HTML code
  1. Response header Information
  2. Server apache-coyote/1.1
  3. Set-cookie jsessionid=072d9b189c4aa9da4d4ad0b6c2c89e50; path=/test
  4. Content-type text/html; charset=iso-8859-1
  5. Transfer-encoding chunked
  6. Content-encoding gzip
  7. Vary accept-encoding
  8. Date Mon, Jan 04:49:38 GMT
  9. Request header Information
  10. Host localhost:8080
  11. User-agent mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.1.6) gecko/20091201 firefox/3.5.6
  12. Accept Text/html,application/xhtml+xml,application/xml; q=0.9,*/*; q=0.8
  13. Accept-language Zh-cn,zh; q=0.5
  14. Accept-encoding gzip,deflate
  15. Accept-charset Gb2312,utf-8; q=0.7,*; q=0.7
  16. Keep-alive 300
  17. Connection keep-alive
  18. Cookie jsessionid=1c8db59ac74495495ed374b13c3d930a
  19. Cache-control max-age=0

No match before the

HTML code
  1. Response header Information
  2. Server apache-coyote/1.1
  3. Content-type text/html; charset=iso-8859-1
  4. Transfer-encoding chunked
  5. Date Mon, Jan 04:54:00 GMT
  6. Request header Information
  7. Host localhost:8080
  8. User-agent mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.1.6) gecko/20091201 firefox/3.5.6
  9. Accept Text/html,application/xhtml+xml,application/xml; q=0.9,*/*; q=0.8
  10. Accept-language Zh-cn,zh; q=0.5
  11. Accept-encoding gzip,deflate
  12. Accept-charset Gb2312,utf-8; q=0.7,*; q=0.7
  13. Keep-alive 300
  14. Connection keep-alive
  15. Cookie jsessionid=072d9b189c4aa9da4d4ad0b6c2c89e50
  16. Cache-control max-age=0

In JSP, the default is to use the cache, if you do not want to use the JSP page can be added

Java code
    1. <%
    2. Response.setheader ("Pragma","No-cache");
    3. Response.setheader ("Cache-control","No-cache");
    4. Response.setdateheader ("Expires", 0);
    5. %>

Note that this is only for pages that do not use caching, images, CSS, JS, or you can use the cached

If you want to control a type that does not use the cache, you can use the filter

Tomcat with Gzip and cache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.