Class HtmlMinifyFilter

java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.broadleafcommerce.common.web.util.HtmlMinifyFilter
All Implemented Interfaces:
jakarta.servlet.Filter, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.EnvironmentAware, org.springframework.core.env.EnvironmentCapable, org.springframework.core.Ordered, org.springframework.web.context.ServletContextAware

@Component("blHtmlMinifyFilter") @ConditionalOnProperty("filter.html.minification.enabled") public class HtmlMinifyFilter extends org.springframework.web.filter.OncePerRequestFilter implements org.springframework.core.Ordered
Enable html minification. All unnecessary white space will be removed from html, inline CSS and inline JS. This should serve to provide some reduction in byte size of the response. This is a suggested pagespeed optimization from Google.

The drawbacks of this filter include: a slight expense in processing the response payload, and the page response is kept entirely in memory to facilitate processing before responding to the caller (usually the http response can be (is) pushed back incrementally to avoid keeping the entire page contents in memory).

The filter is disabled by default. Activate by including this property declaration in your Spring environment property file(s): filter.html.minification.enabled=true.
Author:
Jeff Fischer
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.googlecode.htmlcompressor.compressor.HtmlCompressor
     
    protected Pattern
     

    Fields inherited from class org.springframework.web.filter.OncePerRequestFilter

    ALREADY_FILTERED_SUFFIX

    Fields inherited from class org.springframework.web.filter.GenericFilterBean

    logger

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doFilterInternal(jakarta.servlet.http.HttpServletRequest httpServletRequest, jakarta.servlet.http.HttpServletResponse httpServletResponse, jakarta.servlet.FilterChain filterChain)
     
    int
     
    void
     
    protected boolean
     

    Methods inherited from class org.springframework.web.filter.OncePerRequestFilter

    doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch

    Methods inherited from class org.springframework.web.filter.GenericFilterBean

    addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, setBeanName, setEnvironment, setServletContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • compressor

      protected com.googlecode.htmlcompressor.compressor.HtmlCompressor compressor
    • pattern

      protected Pattern pattern
  • Constructor Details

    • HtmlMinifyFilter

      public HtmlMinifyFilter()
  • Method Details

    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • doFilterInternal

      protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest httpServletRequest, jakarta.servlet.http.HttpServletResponse httpServletResponse, jakarta.servlet.FilterChain filterChain) throws jakarta.servlet.ServletException, IOException
      Specified by:
      doFilterInternal in class org.springframework.web.filter.OncePerRequestFilter
      Throws:
      jakarta.servlet.ServletException
      IOException
    • isWidget

      protected boolean isWidget(String uri)
    • initFilterBean

      public void initFilterBean()
      Overrides:
      initFilterBean in class org.springframework.web.filter.GenericFilterBean