在Web应用程序的jboss服务器中进行新部署后,浏览器缓存文件未更新 [英] Browser cache files not getting updated after a new deployment in jboss server for a web application

查看:179
本文介绍了在Web应用程序的jboss服务器中进行新部署后,浏览器缓存文件未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jboss Server 7.1.1部署Java Web应用程序。
对于js,css,字体文件,浏览器缓存未使用新更改进行更新。每次我们坚持要求客户清除浏览器中的缓存以使新更改生效。

I am using jboss Server 7.1.1 for deploying a java web application. For js, css, font files the browser cache is not getting updated with new changes. Every time we insist the clients to clear cache in their browsers to get the new changes to effect.

是否可以配置任何配置,以便在有新代码时部署后,我可以指导所有要求提供更新文件的请求吗?

is there any configuration which i can configure, so that when a new code is deployed i can guide all the request to be provided with the updated file ?

通过在这个主题上进行搜索,我发现,我们可以编写自定义方法来设置电子标签值。有什么配置可以帮助我做到吗?

by googling on this topic i find that, we can write custom methods to set e-tag value. is there any configuration which can help me doing it?

大多数情况下,我们会进行热部署(在没有停机的情况下将战争文件上传到jboss管理控制台中)。因此,我怀疑自定义电子标签是否会在热部署期间更新,因为我们在服务器启动时对其进行了配置。

most of the time we do a hot deploy (upload the war file in jboss management console with out down time). so i doubt whether the custom e-tag will be updated or not during hot deployment as we configure it on server startup.

或者是否可以在Web中对其进行处理应用程序的web.xml文件?

or is there a way to handle it in web application's web.xml file ?

我需要一个可以使用浏览器缓存的解决方案,直到对js,css和字体文件进行下一次部署为止。我没有设置 expires标题的内容。因为我们没有固定的部署周期。

I need a solution which can use browser cache till next deployment happens for js, css and font files. i don't what to set "expires" header. because we don't have fixed deployment cycles.

让我知道您是否需要更多信息才能找到解决方案。

Let me know if you need more info to arrive at a solution.

推荐答案

由于您正在使用jboss部署应用程序,因此我猜您的页面不是静态的。

Since you are using jboss for deploying your application, I guess that your pages are not static.

一个简单的解决方案,如果您不想弄乱 Cache-Control ,将在每个资源网址旁边添加动态缓存半身。因此,您的资源网址(例如,在 .jsp 内部)如下:

A simple solution if you don't want to mess with Cache-Control, would be to append a dynamic "cache bust" next to each resource url. So your resource urls (e.g. inside a .jsp) would be something like this:

<link rel="stylesheet" href="styles.css?_=${cacheBust}">
<script type="text/javascript" src="script.js?_=${cacheBust}">

现在您需要一个生成新的 cacheBust 每个部署/重新部署的价值。可能是:

Now you need a place to generate a new cacheBust value on each deployment/redeployment. This could be:

在启动时加载的 HttpServlet

@WebServlet(loadOnStartup = 1) 
public class InitServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        super.init();
        getServletContext().setAttribute("cacheBust", UUID.randomUUID().toString());
    }

}

ServletContextListener

@WebListener
public class InitListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        sce.getServletContext().setAttribute("cacheBust", UUID.randomUUID().toString());
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }

}

这篇关于在Web应用程序的jboss服务器中进行新部署后,浏览器缓存文件未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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