开发者

JAWR overrides load of unbundled files

We are using JAWR to bundle CSS and Javascript. It has tremendously decreased the number of hits and bytes downloaded. However, we recently ran into a problem that caused css files that were not "under its control" to return a "not found" (404) code. We have a solution, but I'm wondering if there's a better one.

We defined a CSS bundle for the standard set of css files, and use to load it. We've also got a few non-standard css files, including a pair that define a "legacy" layout. They are loaded with . Finally, the JAWR servlet serving CSS was bound to the url-pattern "*.css" in web.xml. With this configuration, any request for a css file from a tag returned a 404 code. We were unable to find a combination of JAWR property settings that would fix the problem.

The solution we came up with was to modify the JAWR servlet configuration in web.xml, adding the "mapping" parameter:

    <servlet>
    <servlet-name>CssServlet</servlet-name>
    <servlet-class>net.jawr.web.servlet.JawrServlet</servlet-class>
    <init-param>
        <param-name>configLocation</param-name>
        <param-value>/jawr.properties</param-value>
    </init-param>
    <init-param>
        <param-name>type</param-name>
        <param-value>css</param-value>
    </init-param>
    <init-param>
        <param-name>mapping</param-name>
        <param-value>/jawrcss/</param-value>
    </init-param>
    开发者_JAVA百科<load-on-startup>2</load-on-startup>
</servlet>

We changed the url-pattern for the CssServlet to "/jawrcss/*". With this change, css files loaded from the unmodified tags are not touched by JAWR. We lose JAWR's compression abilities for these files, though.

My guess is that in order to have JAWR properly process these files, we need to change the tags to tags, at which point JAWR's "orphan" processing will do the right thing. This is problematic for (at least) a couple of reasons. (1) We're using a shared code base and "cannot" modify some of the files because the others sharing those files aren't using JAWR. (2) Some files load css dynamically using JavaScript, and I don't see how to combine that with the JAWR support.

So, what is/are my question/s?

  1. Is there a way to have JAWR handle (compress, at least) CSS files loaded from tags? (The main question.)
  2. Is there a way to use JAWR with Javascript-loaded CSS?


For javascript loaded CSS (or JS for that matter), you can use JAWR's script loader(explained here - http://jawr.java.net/docs/plain_html.html). Keep in mind that there is a trade-off using script loader(last paragraph of above mentioned page describes that)

Regarding your question 1), by tags you mean which tags ? JSP tags ?


You can use the mapping <init-param> for the servlet, and bind the servlet to that url.

Example from the Jawr servlet documentation:

    ...
    <servlet>
            <servlet-name>JavascriptServlet</servlet-name>
            <servlet-class>net.jawr.web.servlet.JawrServlet</servlet-class>
            <init-param>
                    <param-name>configLocation</param-name>
                    <param-value>/jawr.properties</param-value>
            </init-param>
            <init-param>
                    <param-name>mapping</param-name>
                    <param-value>/jsJawrPath/</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
    </servlet>
    ...

    <servlet-mapping>
            <servlet-name>JavascriptServlet</servlet-name>
            <url-pattern>/jsJawrPath/*</url-pattern>
    </servlet-mapping> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜