Skip to content

Instantly share code, notes, and snippets.

@mxttwoods
Forked from remibantos/wildfly_httpcache.md
Created August 31, 2021 14:31
Show Gist options
  • Select an option

  • Save mxttwoods/f7a6f4ea67fd4c239478f6b1ba3a76aa to your computer and use it in GitHub Desktop.

Select an option

Save mxttwoods/f7a6f4ea67fd4c239478f6b1ba3a76aa to your computer and use it in GitHub Desktop.
Wildfly 8 - HTTP cache headers tuning for rich client web application

Introduction

This Gist describes how to tune HTTP browser cache expiration for static contents served by Wildfly Undertow web server, as per RFC-2616 section 13.

Wildfly configuration

Description

In order to change HTTP browser cache behavior, a "Cache-Control" HTTP header has to be added to static content HTTP responses returned by Undertow.

Undertow subsystem configuration (standalone.xml)

NOTE: "..." means existing xml config elements to be kept

<subsystem xmlns="urn:jboss:domain:undertow:1.2">

  ...

  <server name="default-server">

    ...

    <host name="default-host" alias="localhost">
        ...
        <filter-ref name="custom-max-age" predicate="path-suffix['.js'] or path-suffix ['.json'] or path-suffix ['.html'] or path-suffix ['.css'] or path-suffix ['.jpg'] or path-suffix ['.jpeg'] or path-suffix ['.png'] or path-suffix ['.gif']"/>
    </host>
  </server>

  ...

  <filters>

      ...
      
      <response-header name="custom-max-age" header-name="Cache-Control" header-value="max-age=600, public"/>
  </filters>
</subsystem>

Description

A Cache-Control header will be added to HTTP responses header for static files having extensions: ".js, .json, .html, .css, .jpg, .jpeg, .png, .gif". (Complete list of handlers predicates, such as "path-suffix", is availaible here)

This header has a "max-age=600, public" value which tells to browser to expire these static content files after 600 seconds, as described in RFC-2616 section 14.9.3. (see this other section for public value description)

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment