我的vaadin应用程序中有一个自定义的javascript组件,它扩展了AbstractJavaScriptComponent
。
@JavaScript({"javaScriptConnector.js", "MyComp.js", "MyCompHtml.js"})
public class MyComp extends AbstractJavaScriptComponent {
.....
.....
}
每当我对MyComp.js
进行更改时,我都需要清除浏览器缓存以查看更改。当我开发应用程序时这是可以的,但是一旦应用程序上线,我就不能要求我的用户清除缓存。
有没有办法阻止MyComp.js
的浏览器缓存?我知道你将查询字符串附加到javascript的技巧(例如:MyComp.js?v=1
),但我不知道如何对vaadin AbstractJavaScriptComponent
执行此操作。
答案 0 :(得分:4)
I have overcome this by utilising the resourceCacheTime
parameter of the Vaadin servlet configuration:
@VaadinServletConfiguration(ui = MyUI.class, resourceCacheTime = 0)
Please see DefaultDeploymentConfiguration.class with regards to the default values.
Setting this value to 0
adds the following response header:
cache-control: public, max-age=0, must-revalidate
instructing caches to revalidate this resource every time.
com.vaadin.server.communication.PublishedFileHandler.handleRequest
is where the published file response is created. The issue here is that this is a global setting for all published resources and so the only way to customise this would be to create your published file handler.
Maybe Vaadin would consider adding another option to the @Javascript/@StyleSheet annotation to achieve a more specific resource cache time.