Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your filter have this line:</p> <pre><code>chain.doFilter(httpRequest, new AddExpiresHeaderResponse(httpResponse)); </code></pre> <p>Where the response wrapper looks like:</p> <pre><code>class AddExpiresHeaderResponse extends HttpServletResponseWrapper { public static final String[] CACHEABLE_CONTENT_TYPES = new String[] { "text/css", "text/javascript", "image/png", "image/jpeg", "image/gif", "image/jpg" }; static { Arrays.sort(CACHEABLE_CONTENT_TYPES); } public AddExpiresHeaderResponse(HttpServletResponse response) { super(response); } @Override public void setContentType(String contentType) { if (contentType != null &amp;&amp; Arrays.binarySearch(CACHEABLE_CONTENT_TYPES, contentType) &gt; -1) { Calendar inTwoMonths = GeneralUtils.createCalendar(); inTwoMonths.add(Calendar.MONTH, 2); super.setDateHeader("Expires", inTwoMonths.getTimeInMillis()); } else { super.setHeader("Expires", "-1"); super.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); } super.setContentType(contentType); } } </code></pre> <p>In short, this creates a response wrapper, which, on setting the content type, adds the expires header. (If you want, you can add whatever other headers you need as well). I've been using this filter + wrapper and it works.</p> <p><a href="https://stackoverflow.com/questions/2563344/how-to-add-response-headers-based-on-content-type-getting-content-type-before-th">See this question</a> on one specific problem that this solves, and the original solution by BalusC.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload