This question already has an answer here:
I have a custom javascript component in my vaadin application which extends AbstractJavaScriptComponent
.
@JavaScript({"javaScriptConnector.js", "MyComp.js", "MyCompHtml.js"})
public class MyComp extends AbstractJavaScriptComponent {
.....
.....
}
Whenever I do a change to MyComp.js
, I need to clear my browser cache to see the change. This is ok when I develop the app, but I cannot ask my users to clear cache once the app goes live.
Is there a way to prevent browser caching of MyComp.js
? I am aware of the trick where you append a query string to the javascript (eg: MyComp.js?v=1
) but I have no Idea how I can do that to the vaadin AbstractJavaScriptComponent
.
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.
来源:https://stackoverflow.com/questions/36468846/vaadin-abstractjavascriptcomponent-prevent-browser-javascript-caching