wro4j icon indicating copy to clipboard operation
wro4j copied to clipboard

Smartsprites support

Open dtrunk90 opened this issue 13 years ago • 8 comments

How to integrate Smartsprites to generate (cached) Sprites at runtime?

dtrunk90 avatar Jul 05 '12 08:07 dtrunk90

There is no support for sprites yet and adding it is not a trivial task. I would suggest use CssDataUriProcessor (or FallbackCssDataUriProcessor) which is already supported and has a great impact on performance by drastically reducing number of http requests.

alexo avatar Jul 05 '12 08:07 alexo

DEBUG: ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor - Applying FallbackCssDataUriProcessor processor
DEBUG: ro.isdc.wro.model.resource.processor.decorator.ExceptionHandlingProcessorDecorator - Failed to process the resource: null using processor: FallbackCssDataUriProcessor
DEBUG: ro.isdc.wro.http.WroFilter - RuntimeException occured
java.lang.NullPointerException
    at ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor.process(AbstractCssUrlRewritingProcessor.java:130)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:83)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:83)
    at ro.isdc.wro.model.resource.processor.decorator.ExceptionHandlingProcessorDecorator.process(ExceptionHandlingProcessorDecorator.java:55)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.process(AbstractProcessorDecoratorSupport.java:120)
    at ro.isdc.wro.model.group.processor.GroupsProcessor.applyPostProcessors(GroupsProcessor.java:128)
    at ro.isdc.wro.model.group.processor.GroupsProcessor.doPostProcess(GroupsProcessor.java:102)
    at ro.isdc.wro.model.group.processor.GroupsProcessor.process(GroupsProcessor.java:80)
    at ro.isdc.wro.cache.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:42)
    at ro.isdc.wro.cache.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:23)
    at ro.isdc.wro.cache.AbstractSynchronizedCacheStrategyDecorator.get(AbstractSynchronizedCacheStrategyDecorator.java:52)
    at ro.isdc.wro.manager.ResourceBundleProcessor.serveProcessedBundle(ResourceBundleProcessor.java:74)
    at ro.isdc.wro.manager.WroManager.process(WroManager.java:126)
    at ro.isdc.wro.http.WroFilter.processRequest(WroFilter.java:360)
    at ro.isdc.wro.http.WroFilter.doFilter(WroFilter.java:306)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:203)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

dtrunk90 avatar Jul 06 '12 06:07 dtrunk90

This processor should be used as a preProcessor. I should have thrown a more suggestive exception message for this problem.

alexo avatar Jul 06 '12 07:07 alexo

Now it just doesn't replace the url content for my background. (It can't find the resource, although the images exists)

DEBUG: ro.isdc.wro.model.resource.processor.decorator.MinimizeAwareProcessorDecorator - Using Processor: ro.isdc.wro.model.resource.processor.impl.css.FallbackCssDataUriProcessor@519f8603
DEBUG: ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor - Applying FallbackCssDataUriProcessor processor
DEBUG: ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor - cssUri: /resources/styles/main.less
DEBUG: ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor - urlGroup: ../resources/images/logo.png
DEBUG: ro.isdc.wro.model.resource.processor.impl.css.CssDataUriPreProcessor - replace url for image: ../resources/images/logo.png from css: /resources/styles/main.less
DEBUG: ro.isdc.wro.model.resource.locator.ServletContextUriLocator - locate resource: /resources/styles/../resources/images/logo.png
DEBUG: ro.isdc.wro.model.resource.locator.support.DispatcherStreamLocator - dispatching request to location: /resources/styles/../resources/images/logo.png
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'template' processing GET request for [/template/resources/resources/images/logo.png]
DEBUG: org.springframework.web.servlet.DispatcherServlet - Taking snapshot of request attributes before include
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /resources/resources/images/logo.png
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resources/resources/images/logo.png]
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/resources/images/logo.png] are [/resources/**]
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/resources/images/logo.png] are {}
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/resources/images/logo.png] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@583384c0] and 1 interceptor
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/template/resources/resources/images/logo.png] is: -1
DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Trying relative path [resources/images/logo.png] against base location: ServletContext resource [/resources/]
DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - No matching resource found - returning 404
DEBUG: ro.isdc.wro.http.support.RedirectedStreamServletResponseWrapper - Error detected with code: 404 and message: 
DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'template': assuming HandlerAdapter completed request handling
DEBUG: org.springframework.web.servlet.DispatcherServlet - Restoring snapshot of request attributes after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.HandlerMapping.introspectTypeLevelMapping] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.DispatcherServlet.FLASH_MAP_MANAGER] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.DispatcherServlet.THEME_SOURCE] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.DispatcherServlet.THEME_RESOLVER] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.DispatcherServlet.CONTEXT] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.core.convert.ConversionService] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.HandlerMapping.pathWithinHandlerMapping] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.DispatcherServlet.OUTPUT_FLASH_MAP] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.HandlerMapping.bestMatchingPattern] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Removing attribute [org.springframework.web.servlet.DispatcherServlet.LOCALE_RESOLVER] after include
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'template' processing GET request for [/template]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /resources/resources/images/logo.png
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resources/resources/images/logo.png]
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/resources/images/logo.png] are [/resources/**]
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/resources/images/logo.png] are {}
DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/resources/images/logo.png] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@583384c0] and 1 interceptor
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/template] is: -1
DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Trying relative path [resources/images/logo.png] against base location: ServletContext resource [/resources/]
DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - No matching resource found - returning 404
DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'template': assuming HandlerAdapter completed request handling
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: ro.isdc.wro.model.resource.locator.support.DispatcherStreamLocator - [FAIL] Error while dispatching the request for location /resources/styles/../resources/images/logo.png
WARN : ro.isdc.wro.model.resource.locator.support.DispatcherStreamLocator - Wrong or empty resource with location: /resources/styles/../resources/images/logo.png
DEBUG: ro.isdc.wro.model.resource.locator.ServletContextUriLocator - retrieving servletContext stream for uri: /resources/styles/../resources/images/logo.png
ERROR: ro.isdc.wro.model.resource.locator.ServletContextUriLocator - [FAIL] reading resource from /resources/styles/../resources/images/logo.png
WARN : ro.isdc.wro.model.resource.locator.ServletContextUriLocator - Wrong or empty resource with location: /resources/styles/../resources/images/logo.png
WARN : ro.isdc.wro.model.resource.processor.impl.css.CssDataUriPreProcessor - [FAIL] extract dataUri from: /resources/styles/../resources/images/logo.png, because: Exception while reading resource from /resources/styles/../resources/images/logo.png. A possible cause: using CssUrlRewritingProcessor before CssDataUriPreProcessor.
DEBUG: ro.isdc.wro.model.resource.processor.impl.css.AbstractCssUrlRewritingProcessor - replaced old Url: [../resources/images/logo.png] with: [../resources/images/logo.png].
DEBUG: ro.isdc.wro.model.resource.processor.decorator.MinimizeAwareProcessorDecorator - Using Processor: ro.isdc.wro.model.resource.processor.decorator.LazyProcessorDecorator@401758d2
DEBUG: ro.isdc.wro.extensions.processor.support.less.LessCss - StopWatch '': running time (millis) = 30

Code:

#logo
{
    background-image: url(../images/logo.png);
    height: 43px;
    width: 190px;
}

dtrunk90 avatar Jul 06 '12 08:07 dtrunk90

I don't like this base64 encoding stuff. Will Smartsprites be added in the near future?

dtrunk90 avatar Jul 06 '12 08:07 dtrunk90

One of the reason why you can get 404 when using cssDataUri is as log says:

    A possible cause: using CssUrlRewritingProcessor before CssDataUriPreProcessor.

In order to make it work, use CssDataUriPreProcessor (or FallbackCssDataUriPreProcessor) before the CssUrlRewritingProcessor.

The base64 encoding is a very common and good practice. However if you don't like it, you can easily switch it off by removing the processor.

The smartsprites support is not a priority at this moment, but if there are any contributions I would gladly include them in future release.

alexo avatar Jul 06 '12 08:07 alexo

Lol, didn't noticed the text after [FAIL] extract dataUri from ... :-) thanks now it works. I'll see what I can do adding this functionality. Need time and information on how to write my own processor.

dtrunk90 avatar Jul 06 '12 09:07 dtrunk90

You can find more documentation about how to write a custom processor here: http://code.google.com/p/wro4j/wiki/ResourceProcessors

alexo avatar Jul 06 '12 10:07 alexo