How do I prevent browser caching with Play?

I haven't tested it, but it looks like the http.cacheControl configuration setting might work.

http.cacheControl

HTTP Response headers control for static files: sets the default max-age in seconds, telling the user’s browser how long it should cache the page. This is only read in prod mode, in dev mode the cache is disabled. For example, to send no-cache:

http.cacheControl=0

Default: 3600 – set cache expiry to one hour.


Play framework response object has a setHeader method. You can add the headers you want like this, for example:

response.setHeader("Cache-Control", "no-cache");