Skip to content

Instantly share code, notes, and snippets.

@juandbc
Forked from remibantos/wildfly_httpcache.md
Last active July 26, 2017 05:18
Show Gist options
  • Save juandbc/616cf92bc0e9288cdc521465f969ee02 to your computer and use it in GitHub Desktop.
Save juandbc/616cf92bc0e9288cdc521465f969ee02 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="cache-control" 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="cache-control" header-name="Cache-Control" header-value="no-cache"/>
  </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