4 Replies Latest reply on Apr 20, 2017 3:53 AM by valsaraj007

    HTTP Etag on wildfly 10.

    tiago.matias

      Hello,

       

      I'm trying to add ETAG's to my http resposes. The objective is to make the browser cache static contents like javascript, CSS and image files. I've added the vary-header and a cache-control header (with max-age=600, public) to the responses. However the browser refuses to cache these files (confirmed with fiddler).

       

      As far as I could gather, an Etag header is necessary but I can find no documentation explaining how to configure it for Undertow. This is my configuration so far:

       <subsystem xmlns="urn:jboss:domain:undertow:3.1">
                  <buffer-cache name="default"/>
                  <server name="default-server">
                      <http-listener name="default" socket-binding="http" redirect-socket="https"/>
                      <host name="default-host" alias="localhost">
                          <location name="/" handler="welcome-content"/>
                          <filter-ref name="gzipFilter" predicate="exists['%{o,Content-Type}'] and regex[pattern='(?:application/javascript|text/css|text/html|text/xml|application/json)(;.*)?', value=%{o,Content-Type}, full-match=true]"/>
                          <filter-ref name="Vary-header"/>
                          <filter-ref name="custom-max-age" predicate="path-suffix['.js'] or path-suffix ['.json'] or path-suffix ['.html'] or path-suffix ['.css'] or path-suffix ['.jpg'] or path-suffix ['.jpeg'] or path-suffix ['.png'] or path-suffix ['.gif']"/>
                      </host>
                  </server>
                  <servlet-container name="default">
                      <jsp-config/>
                      <websockets/>
                  </servlet-container>
                  <handlers>
                      <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
                  </handlers>
                  <filters>
                      <response-header name="Vary-header" header-name="Vary" header-value="Accept-Encoding"/>
                      <response-header name="custom-max-age" header-name="Cache-Control" header-value="max-age=600, public"/>
                      <gzip name="gzipFilter"/>
                  </filters>
              </subsystem>
      

       

      Can anyone share a solution?

       

      Many thanks in advance!

        • 1. Re: HTTP Etag on wildfly 10.
          jdev123

          Did you find the answer to this question maybe? Thanks

          • 2. Re: HTTP Etag on wildfly 10.
            tiago.matias

            No. Honestely, given the lack of response, the lack of information and the general obscurity of Wildfly documentation, I'm not recommending anyone using Wildfly to serve static content. Put your servlets there. Images, Javascript, CSS, etc... you'll be better served with an Apache server or even a Microsoft IIS.

             

            Sorry

            2 of 2 people found this helpful
            • 3. Re: HTTP Etag on wildfly 10.
              jdev123

              Thanks for answer.

              I resolved this issue by adding interceptor when requesting fonts files:

               

                <interceptor>
                     <mapping path="/styles/fonts/**" />
                     <beans:bean class="com.utils.FontInterceptor"/>
                 </interceptor>
              

               

              And then in interceptor in preHandle method just add headers whatever you want.

               

              public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception
                  {
                     Calendar calendar = Calendar.getInstance();
                      calendar.add(Calendar.YEAR, 1);
              
                      response.setHeader("Cache-Control", "max-age=31536000, public");
                      response.setDateHeader("Expires", calendar.getTime().getTime());
                      response.setHeader("Pragma","cache");
                      return true;
                  }
              

               

              Cheers.

              1 of 1 people found this helpful
              • 4. Re: HTTP Etag on wildfly 10.
                valsaraj007

                Since we have wildfly load balancer available, is it good idea to serve static content from wildfly load balancer? What are the optimizations we can apply on this LB?