Vaadin AbstractJavaScriptComponent:阻止浏览器javascript缓存 [英] Vaadin AbstractJavaScriptComponent: prevent browser javascript caching

查看:75
本文介绍了Vaadin AbstractJavaScriptComponent:阻止浏览器javascript缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的vaadin应用程序中有一个自定义javascript组件,扩展了 AbstractJavaScriptComponent

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 {
.....
.....
}

每当我更改为 MyComp.js ,我需要清除浏览器缓存以查看更改。当我开发应用程序时,这是可以的,但是一旦应用程序上线,我无法要求我的用户清除缓存。

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.

有没有办法防止浏览器缓存 MyComp.js ?我知道你在javascript中附加查询字符串的技巧(例如: MyComp.js?v = 1 )但我不知道如何做到这一点vaadin AbstractJavaScriptComponent

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.

推荐答案

我已经通过利用 resourceCacheTime Vaadin servlet配置的参数:

I have overcome this by utilising the resourceCacheTime parameter of the Vaadin servlet configuration:

@VaadinServletConfiguration(ui = MyUI.class, resourceCacheTime = 0)

请参阅 DefaultDeploymentConfiguration.class 关于默认值。

将此值设置为 0 添加以下响应标头:

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 是创建发布文件响应的位置。这里的问题是,这是所有已发布资源的全局设置,因此自定义此选项的唯一方法是创建已发布的文件处理程序。

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.

也许Vaadin会考虑在@Javascript / @ StyleSheet批注中添加另一个选项,以实现更具体的资源缓存时间。

Maybe Vaadin would consider adding another option to the @Javascript/@StyleSheet annotation to achieve a more specific resource cache time.

这篇关于Vaadin AbstractJavaScriptComponent:阻止浏览器javascript缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆