spring - How to have WRO answer with a http 304 not modified? -


we serving javascript resources (and others) via wro in our webapp. on prod environment, browser gets (for example) app.js angular webapp's content 'expires' headers 1 year in future.

meaning subsequent requests browser takes cache without request server. if deploy new version of webapp, browser not new version, takes local cache.

the goal configure wro or/and spring headers correctly set have browser perform request each time, , server return 304 not modified. have clients automatically "updated" uppon new deployment. did achieve this?

we use spring's java configuration:

@configuration public class wro4jconfiguration {     @value("${app.webapp.web.minimize}") private string minimize;  @value("${app.webapp.web.disablecache}") private string disablecache;  @autowired private environment env;  @bean(name = "wrofilter") public wrofilter wrofilter() {     configurablewrofilter filter = new configurablewrofilter();     filter.setwromanagerfactory(new wro4jmanagerfactory());     filter.setwroconfigurationfactory(createproperties());     return filter; }  private propertywroconfigurationfactory createproperties() {     properties props = new properties();     props.setproperty("jmxenabled", "false");     props.setproperty("debug", string.valueof(!env.acceptsprofiles(envconstants.prod)));     props.setproperty("gzipresources", "false");     props.setproperty("ignoremissingresources", "true");     props.setproperty("minimizeenabled", minimize);     props.setproperty("resourcewatcherupdateperiod", "0");     props.setproperty("modelupdateperiod", "0");     props.setproperty("cachegzippedcontent", "false");     // let's see if server-side cache disabled (dev only)     if (boolean.valueof(disablecache)) {         props.setproperty("resourcewatcherupdateperiod", "1");         props.setproperty("modelupdateperiod", "5");     }     return new propertywroconfigurationfactory(props); } } 

based on alex's information , documentation reference, ended overriding wrofilter.setresponseheaders put appropriate expire values. working fine. wro takes care of setting etag, date , others, overwrite expiration delay , date.

@configuration public class wro4jconfiguration {      @value("${app.webapp.web.browsercache.maxageinhours}")     private string maxageinhours;      @bean(name = "wrofilter")     public wrofilter wrofilter() {         configurablewrofilter filter = createfilter();          filter.setwromanagerfactory(new wro4jmanagerfactory());         filter.setwroconfigurationfactory(createproperties());          return filter;     }      private configurablewrofilter createfilter() {         return new configurablewrofilter() {              private final int browser_cache_hours = integer.parseint(maxageinhours);             private final int browser_cache_seconds = browser_cache_hours * 60 * 60;              @override             protected void setresponseheaders(final httpservletresponse response){                 super.setresponseheaders(response);                  if (!getconfiguration().isdebug()) {                     zoneddatetime cacheexpires = zoneddatetime.of(localdatetime.now(), zoneid.of("gmt")).plushours(browser_cache_hours);                     string cacheexpiresstr = cacheexpires.format(datetimeformatter.rfc_1123_date_time);                      response.setheader(httpheader.expires.tostring(), cacheexpiresstr);                     response.setheader(httpheader.cache_control.tostring(), "public,  max-age=" + browser_cache_seconds);                 }             }         };     }      // other config methods  } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -