Class VersionedResourceHandler

  • All Implemented Interfaces:

    public class VersionedResourceHandler
    extends DefaultResourceHandler
    Automatically adds version parameter with query string name v to all resource URLs so that the browser cache will be busted whenever the version parameter changes.

    NOTE: if resource URL already has v query string parameter, or when it is URL-rewritten to not include "/jakarta.faces.resource" path anymore, then these will be ignored.


    To get it to run, this handler needs be registered as follows in faces-config.xml:


    And the version parameter needs to be configured as follows in web.xml:

         <!-- Version parameter value could be any hardcoded string here, or any object property from managed bean -->

    Example Code (GitHub)

    Lenny Primak
    • Field Detail


        public static final String PARAM_NAME_VERSION
        The context parameter name to specify value of the version to be appended to the resource URL.
        See Also:
        Constant Field Values
    • Constructor Detail

      • VersionedResourceHandler

        public VersionedResourceHandler​(ResourceHandler wrapped)
        Creates a new instance of this versioned resource handler which wraps the given resource handler. This will also initialize the version based on the context parameter.
        wrapped - The resource handler to be wrapped.
    • Method Detail

      • decorateResource

        public Resource decorateResource​(Resource resource)
        Description copied from class: DefaultResourceHandler
        Decorate the given resource. This will only be called if no library-specific resource has been requested.

        The default implementation just returns the given resource unmodified.

        decorateResource in class DefaultResourceHandler
        resource - The resource to be decorated.
        The decorated resource.