Playback and Java Caching

I run the application with Play and Java, and I need to set the expiration date for various types of assets: images, css, javascript, etc.

The conf / routes file has the following:

GET /assets/*file controllers.Assets.at(path="/public", file) 

I managed to set the expiration date for one separate file in application.conf :

 "assets.cache./public/js/pages/validation.js"="max-age=7200" 

But I can not install it for the entire folder. I tried

 "assets.cache./public/js/pages/*.js"="max-age=7200" "assets.cache./public/js/pages/*"="max-age=7200" 

but nothing happens. I was hoping to set an expiration date for everything in the / js / pages folder.

I also tried

 assets.defaultCache="max-age=7200" 

according to the instructions at http://www.jamesward.com/2014/04/29/optimizing-static-asset-loading-with-play-framework

and

 http.cacheControl=7200 

to the documentation http://www.playframework.com/documentation/1.2.3/configuration#http

and not one of these works. The changes above were made in application.conf.

I know that there is a way to do the same by specifying controllers that change the answer () for the routes I want to set the expiration date for: Far future Expires header for static content

But I would like to know how to set the expiration date for the assets from the application.conf file.

Our application runs on S3 Linux instances, so setting an expiration date on the server is not an option.

Thanks!

+8
java browser-cache playframework expires-header
source share
1 answer

The Play Framework does not support "assets.cache./public/js/pages/*.js"="max-age=7200" but assets.defaultCache="max-age=7200" should work.

In debug / dev mode (launching the application using playback), assets.defaultCache ignored, so it is always "no-cache". Make sure you run it in prod mode (when you start the game).

I can’t find the link in the docs, but it can be checked at https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/play/api/controllers/Assets.scala AssetInfo::cacheControl function

+4
source share

All Articles