Leverage browser caching in Google App Engine

November 9, 2013

I’m working on a project that allows friends to work out who owes cash to whom after a joint event: it’s called Kittysplit and is built in Java / Google App Engine.

Running the site through Google’s wonderful page speed insights tool resulted in this recommendation: “Leverage browser caching”.

Here’s what you need to do to implement caching for static files.

Add the following to appengine-web.xml (remembering to substitute the correct directory for /STATIC_DIR/).

 <!-- Set a long cache expiration time for static files -->
 <static-files>
    <include path="/STATIC_DIR/**" expiration="365d"/>
    <include path="/**.html">
  </static-files>

For some reason app engine does not serve static HTML files unless the second include is also present.

More information can be found here