- All Implemented Interfaces:
FacesWrapper<ResourceHandler>
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe context parameter name to configure the source map pattern.Fields inherited from class org.omnifaces.resourcehandler.DefaultResourceHandler
RES_NOT_FOUNDFields inherited from class jakarta.faces.application.ResourceHandler
FACES_SCRIPT_LIBRARY_NAME, FACES_SCRIPT_RESOURCE_NAME, JSF_SCRIPT_LIBRARY_NAME, JSF_SCRIPT_RESOURCE_NAME, LOCALE_PREFIX, RESOURCE_CONTRACT_XML, RESOURCE_EXCLUDES_DEFAULT_VALUE, RESOURCE_EXCLUDES_PARAM_NAME, RESOURCE_IDENTIFIER, WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME, WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME -
Constructor Summary
ConstructorsConstructorDescriptionSourceMapResourceHandler(ResourceHandler wrapped) Creates a new instance of this source map resource handler which wraps the given resource handler. -
Method Summary
Modifier and TypeMethodDescriptiondecorateResource(Resource resource, String resourceName, String libraryName) Decorate the given resource.Methods inherited from class org.omnifaces.resourcehandler.DefaultResourceHandler
createResource, createResource, createResource, createResourceFromLibrary, decorateResource, getLibraryNameMethods inherited from class jakarta.faces.application.ResourceHandlerWrapper
createResourceFromId, createViewResource, getRendererTypeForResourceName, getViewResources, getViewResources, getWrapped, handleResourceRequest, isResourceRendered, isResourceRequest, isResourceURL, libraryExists, markResourceRendered
-
Field Details
-
PARAM_NAME_SOURCE_MAP_PATTERN
The context parameter name to configure the source map pattern.- See Also:
-
-
Constructor Details
-
SourceMapResourceHandler
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.
-
-
Method Details
-
decorateResource
Description copied from class:DefaultResourceHandlerDecorate the given resource. This will only be called if no library-specific resource has been requested.The default implementation delegates to
DefaultResourceHandler.decorateResource(Resource).- Overrides:
decorateResourcein classDefaultResourceHandler- Parameters:
resource- The resource to be decorated.resourceName- The resource name.libraryName- The library name.- Returns:
- The decorated resource.
-