Class SourceMapResourceHandler
- java.lang.Object
-
- jakarta.faces.application.ResourceHandler
-
- jakarta.faces.application.ResourceHandlerWrapper
-
- org.omnifaces.resourcehandler.DefaultResourceHandler
-
- org.omnifaces.resourcehandler.SourceMapResourceHandler
-
- All Implemented Interfaces:
FacesWrapper<ResourceHandler>
public class SourceMapResourceHandler extends DefaultResourceHandler
This
ResourceHandler
implementation will set theSourceMap
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 theSourceMap
response header, and register theSourceMapResourceHandler
infaces-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
Fields Modifier and Type Field Description static String
PARAM_NAME_SOURCE_MAP_PATTERN
The context parameter name to configure the source map pattern.-
Fields inherited from class org.omnifaces.resourcehandler.DefaultResourceHandler
FACES_SCRIPT_RESOURCE_NAME, RES_NOT_FOUND
-
Fields inherited from class jakarta.faces.application.ResourceHandler
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
Constructors Constructor Description SourceMapResourceHandler(ResourceHandler wrapped)
Creates a new instance of this source map resource handler which wraps the given resource handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource
decorateResource(Resource resource, String resourceName, String libraryName)
Decorate the given resource.-
Methods inherited from class org.omnifaces.resourcehandler.DefaultResourceHandler
createResource, createResource, createResource, createResourceFromLibrary, decorateResource, getLibraryName
-
Methods inherited from class jakarta.faces.application.ResourceHandlerWrapper
createResourceFromId, createViewResource, getRendererTypeForResourceName, getViewResources, getViewResources, getWrapped, handleResourceRequest, isResourceRendered, isResourceRequest, isResourceURL, libraryExists, markResourceRendered
-
-
-
-
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.
-
-
Method Detail
-
decorateResource
public Resource decorateResource(Resource resource, String resourceName, String libraryName)
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 delegates to
DefaultResourceHandler.decorateResource(Resource)
.- Overrides:
decorateResource
in classDefaultResourceHandler
- Parameters:
resource
- The resource to be decorated.resourceName
- The resource name.libraryName
- The library name.- Returns:
- The decorated resource.
-
-