Class SourceMapResourceHandler

  • All Implemented Interfaces:
    FacesWrapper<ResourceHandler>

    public class SourceMapResourceHandler
    extends DefaultResourceHandler

    This ResourceHandler implementation will set the SourceMap response header with the correctly mapped request path to any discovered source map of any CSS and JS resource.

    By default, CSS and JS minifiers will embed the path to the source map in a comment like as the below one in our own omnifaces.js.

     //# sourceMappingURL=omnifaces.js.map
     

    The web browser will then attempt to resolve this against the current request URL, but this would fail with a 404 error because the Faces mapping such as *.xhtml is missing.

    In order to sovle that, first configure your minifier to disable writing the # sourceMappingURL comment, otherwise that would still take precedence over the SourceMap response header, and register the SourceMapResourceHandler in faces-config.xml as below.

     <application>
         <resource-handler>org.omnifaces.resourcehandler.SourceMapResourceHandler</resource-handler>
     </application>
     

    By default, the SourceMapResourceHandler will use *.map pattern to create the source map URL. In other words, it's expected that the source map file is located in exactly the same folder and has the .map extension. In case you need a different pattern, e.g. sourcemaps/*.map, then you can set that via the "org.omnifaces.SOURCE_MAP_RESOURCE_HANDLER_PATTERN" context parameter.

     <context-param>
         <param-name>org.omnifaces.SOURCE_MAP_RESOURCE_HANDLER_PATTERN</param-name>
         <param-value>sourcemaps/*.map</param-value>
     </context-param>
     

    Note that the SourceMap response header will only be set when the target source map file actually exists.

    Since:
    3.1
    Author:
    Bauke Scholtz
    • Field Detail

      • PARAM_NAME_SOURCE_MAP_PATTERN

        public static final String PARAM_NAME_SOURCE_MAP_PATTERN
        The context parameter name to configure the source map pattern.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SourceMapResourceHandler

        public SourceMapResourceHandler​(ResourceHandler wrapped)
        Creates a new instance of this source map resource handler which wraps the given resource handler. This will also initialize the source map pattern based on the context parameter.
        Parameters:
        wrapped - The resource handler to be wrapped.