我們正在通過我們的web應用程序提供javascript資源(和其他)。 在PROD環境中,瀏覽器將在未來一年內獲得(例如)app.js angular webapp的內容,其中包含'expires'標頭。如何讓WRO回答一個未被修改的http 304?
這意味着對於後續請求,瀏覽器將其從緩存中取出而不需要請求到服務器。 如果我們部署新版本的webapp,瀏覽器不會獲得新版本,因爲它會從本地緩存中獲取。
目標是配置wro或/和spring,以便正確設置標題以使瀏覽器每次執行請求,並且服務器返回304未修改。所以我們會讓客戶自動「更新」新的部署。 有人已經做到了嗎?
我們使用Spring的Java配置:
@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 is disabled (DEV only)
if (Boolean.valueOf(disableCache)) {
props.setProperty("resourceWatcherUpdatePeriod", "1");
props.setProperty("modelUpdatePeriod", "5");
}
return new PropertyWroConfigurationFactory(props);
}
}