Code Monkey home page Code Monkey logo

wro4j-runtime-taglib's Introduction

Build Status Build Status Maven Central

Features

  1. Run-time support for namingStrategy configuration option.
  2. Configurable rendering of resource URIs. Provides resourceUriStrategy configuration option.
  3. Allows for rendering of external and protected unprocessed resources.
  4. Legacy code friendly. Tag library allows direct access to optimized resources.
  5. Wrapper-based implementation. Tag library shouldn't affect your wro4j customizations.
  6. Lazy-loading. Defer initialization of data until it's first required.
  7. Separate tag library context for web applications. Tag library stores it's data in servlet context scope.
  8. Exhausted caching of tag library data. Creates cache using cachingStrategy.
  9. Adaptable to resource changes. Supports resourceWatcherUpdatePeriod.

Usage

Prerequisites

  <listener>
    <listener-class>ro.isdc.wro.http.WroServletContextListener</listener-class>
  </listener>

  <filter>
    <filter-name>WroContextFilter</filter-name>
    <filter-class>ro.isdc.wro.http.WroContextFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>WroContextFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

Installation

  1. Add ContextListener to web.xml after WroServletContextListener
<listener>
  <listener-class>com.github.lifus.wro4j_runtime_taglib.servlet.TaglibServletContextListener</listener-class>
</listener>
  1. include the following tag library directive in every JSP in which optimized resources are used
<%@ taglib prefix="wro" uri="https://github.com/lifus/wro4j-runtime-taglib"%>
  1. Replace usages of optimized resources with tags
<wro:script group="all" />
<wro:stylesheet group="all" />

Configuration

Use wro.properties.

resourceUriStrategy

Default: versioned.

Resources that should be rendered. Specify one of the following values:

Value Description
versioned Render optimized resources and version their URIs
unoptimized Render unprocessed resources. Supported uriLocators are servletContext and uri.

optimizedResourcesRootStrategy

Default: inferred.

Strategy to find the root of optimized resources. Specify one of the following values:

Value
inferred Use value of the first url-pattern for the first WroFilter in web.xml
predefined Use value of optimizedResourcesRoot property in wro.properties

optimizedResourcesRoot

The root of optimized resources. Required when optimizedResourcesRootStrategy is predefined, ignored when optimizedResourcesRootStrategy is inferred.

Example: optimizedResourcesRoot=/wro/

resourceDomain

The domain that is used to serve resources to your users.

Example: resourceDomain=//your-cdn.com

License

This project is available under the Apache License, Version 2.0.

wro4j-runtime-taglib's People

Contributors

lifus avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

wro4j-runtime-taglib's Issues

hash not updating when css content changes

I'm not sure if it's an error in my configuration, or a bug, but it seems that a webapp restart is required for the hash of a group to update.

Eg. I can update a less file, and see it's content change when i reload the resulting css for that particular group, using the same resource name / hash. If I restart the webapp, then I get an exception, eg.

ro.isdc.wro.WroRuntimeException: No such group available in the model: external-d3a9f9523f74c740f8a9daaa03412331

I didn't realize this until I got my cache headers set up properly, so I didn't see that the group hash didn't change when the content changed until now. Here's my current configuration;

gzipResources=true
minimizeEnabled=true
ignoreMissingResources=false
jmxEnabled=true
hashStrategy=MD5
namingStrategy=hashEncoder
cacheUpdatePeriod=18000
modelUpdatePeriod=18000

optimizedResourcesRootStrategy=predefined
optimizedResourcesRoot=/resources/wro/

preProcessors=less4j,cssUrlRewriting,lessCssImport,semicolonAppender
postProcessors=cssMinJawr,jsMin
uriLocators=servletContext,uri,classpath

I've tried both the master branch and the resourceDomain branch.

Feature request: optional domain attribute to tag, or as a configuration parameter

We use a CDN for our production environment, so I add a hostname prefix to resources for the production Spring environment profile. I think an optional hostname could either be added as an attribute to the script and style taglib, or through the wro.properties file.

Alternatively, there could be a third tag that merely provides the path / url to the resource with the correct fingeprint, if needed eg for use in Javascript. The CDN hostname could then be prefixed manually.

Configure taglib with spring

It would be very convenient if the taglib could be configured through Spring. This is especially handy when the wro4j filter and manager is itself configured through Spring.

recurring no context problem

I sporadically get these, am thinking it might be a timing issue, since a page reload often results in a properly rendered page;

ro.isdc.wro.WroRuntimeException: No context associated with CURRENT request cycle!
at ro.isdc.wro.config.Context.validateContext(Context.java:124)
at ro.isdc.wro.config.Context.get(Context.java:107)
at ro.isdc.wro.model.group.processor.InjectorBuilder$17.create(InjectorBuilder.java:254)
at ro.isdc.wro.model.group.processor.InjectorBuilder$17.create(InjectorBuilder.java:252)
at ro.isdc.wro.util.ProxyFactory$1.invoke(ProxyFactory.java:70)
at com.sun.proxy.$Proxy356.getConfig(Unknown Source)
at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.getResourceWatcherUpdatePeriod(DefaultSynchronizedCacheStrategyDecorator.java:109)
at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.shouldWatchForChange(DefaultSynchronizedCacheStrategyDecorator.java:154)
at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.onBeforeGet(DefaultSynchronizedCacheStrategyDecorator.java:142)
at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.onBeforeGet(DefaultSynchronizedCacheStrategyDecorator.java:35)
at ro.isdc.wro.cache.support.AbstractSynchronizedCacheStrategyDecorator.get(AbstractSynchronizedCacheStrategyDecorator.java:40)
at com.github.lifus.wro4j_runtime_taglib.model.group.name.DefaultVersionedGroupNameFactory.getInputStream(DefaultVersionedGroupNameFactory.java:58)
at com.github.lifus.wro4j_runtime_taglib.model.group.name.DefaultVersionedGroupNameFactory.create(DefaultVersionedGroupNameFactory.java:40)
at com.github.lifus.wro4j_runtime_taglib.model.resource.uri.strategy.VersionedResourceUriStrategy.getPathRelativeToWroRoot(VersionedResourceUriStrategy.java:62)
at com.github.lifus.wro4j_runtime_taglib.model.resource.uri.strategy.VersionedResourceUriStrategy.getUriOfOptimizedResource(VersionedResourceUriStrategy.java:49)
at com.github.lifus.wro4j_runtime_taglib.model.resource.uri.strategy.VersionedResourceUriStrategy.getResourcesUris(VersionedResourceUriStrategy.java:45)
at com.github.lifus.wro4j_runtime_taglib.model.resource.uri.strategy.ConfigurableResourceUriStrategy.getResourcesUris(ConfigurableResourceUriStrategy.java:110)
at com.github.lifus.wro4j_runtime_taglib.model.resource.uri.cache.ResourceUriCacheStrategyDecorator.loadValue(ResourceUriCacheStrategyDecorator.java:38)
at com.github.lifus.wro4j_runtime_taglib.model.resource.uri.cache.ResourceUriCacheStrategyDecorator.loadValue(ResourceUriCacheStrategyDecorator.java:17)
at ro.isdc.wro.cache.support.AbstractSynchronizedCacheStrategyDecorator.get(AbstractSynchronizedCacheStrategyDecorator.java:55)
at com.github.lifus.wro4j_runtime_taglib.context.TaglibContext.getResourceUris(TaglibContext.java:64)
at com.github.lifus.wro4j_runtime_taglib.tag.AbstractWroElementTag.getResourceUris(AbstractWroElementTag.java:50)
at com.github.lifus.wro4j_runtime_taglib.tag.AbstractWroElementTag.getOutput(AbstractWroElementTag.java:42)
at com.github.lifus.wro4j_runtime_taglib.tag.AbstractHtmlElementTag.doTag(AbstractHtmlElementTag.java:23)

My filter mapping order is the following;

<filter-mapping>
    <filter-name>WroContextFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>ERROR</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
    <filter-name>isUserInRoleFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>WroFilter</filter-name>
    <url-pattern>/resources/wro/*</url-pattern>
    <url-pattern>/admin/wro/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>siteMeshFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

<filter-mapping>
    <filter-name>httpMethodFilter</filter-name>
    <servlet-name>appServlet</servlet-name>
</filter-mapping>
<filter-mapping>
    <filter-name>sessionRegisterFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>pageViewCounter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.