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 JSF 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.
Modifier and Type | Field and Description |
---|---|
static String |
PARAM_NAME_SOURCE_MAP_PATTERN
The context parameter name to configure the source map pattern.
|
RES_NOT_FOUND
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 and Description |
---|
SourceMapResourceHandler(ResourceHandler wrapped) |
Modifier and Type | Method and Description |
---|---|
Resource |
decorateResource(Resource resource,
String resourceName,
String libraryName)
Decorate the given resource.
|
createResource, createResource, createResource, createResourceFromLibrary, decorateResource, getLibraryName
createResourceFromId, createViewResource, getRendererTypeForResourceName, getViewResources, getViewResources, getWrapped, handleResourceRequest, isResourceRendered, isResourceRequest, isResourceURL, libraryExists, markResourceRendered
public static final String PARAM_NAME_SOURCE_MAP_PATTERN
public SourceMapResourceHandler(ResourceHandler wrapped)
public Resource decorateResource(Resource resource, String resourceName, String libraryName)
DefaultResourceHandler
The default implementation delegates to DefaultResourceHandler.decorateResource(Resource)
.
decorateResource
in class DefaultResourceHandler
resource
- The resource to be decorated.resourceName
- The resource name.libraryName
- The library name.Copyright © 2012–2020 OmniFaces. All rights reserved.