Rewriting with JSF 2 h:outputStylesheet / h:outputScript failed

Splash Forums PrettyFaces Users Rewriting with JSF 2 h:outputStylesheet / h:outputScript failed

This topic contains 7 replies, has 3 voices, and was last updated by  Lincoln Baxter III 11 years, 3 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #17792

    Oleg
    Participant

    Hello,

    I’ve started to use PrettyFaces with JSF 2 and encountered a big problem. Maybe I’m doing something wrong. I want to avoid resource caching (JS, CSS files) and use in my web app JSF 2 tag h:outputStylesheet / h:outputScript with a special prepared URL:

    <h:outputScript library=”js” name=”xtime=#{applicationConfiguration.buildTime}/ip-jsftoolkit.js” target=”head”/>

    buildTime in the URL is generated if we build our war archive. The part with “xtime” should be removed by using of this configuration:

    <pretty-config xmlns=”http://ocpsoft.com/prettyfaces/3.1.0″

    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

    xsi:schemaLocation=”http://ocpsoft.com/prettyfaces/3.1.0 http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.1.0.xsd“>

    <rewrite match=”xtime=(d*)/(.+)” substitute=”$2″ redirect=”chain”/>

    </pretty-config>

    Pattern and filter-mapping are correct, it’s not a problem. The problem is that HttpServletResponse.encodeURL() is not called if JSF tries to build the URL. I’ve not found this call in

    Resource resource = context.getApplication().getResourceHandler().createResource(name, library);

    Result: No rewriting is possible and we have many warnungs like

    13:05:54,312 WARNING [application] JSF1064: Ressource xtime=1287054180000/ip-jsftoolkit.js from library js can not be found or …..

    What is a possible solution for this issue?

    Thanks in advance!

    #20245

    Oleg
    Participant

    I think, I have to rewrite ScriptRenderer and StylesheetRenderer.

    #20246

    domdorn
    Participant

    Get rid of this xtime=… thing in the url and simply make sure, you’re resources are put in /resources/yourlibrary/1287054180000/ip-jsftoolkit.js when creating the war.

    jsf’s resource loading will automatically find the newest version and append a version=1287054180000 to the generated url which then gets resolved back and your resource is displayed. no need to do anything with prettyfaces here.

    http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature5

    #20247

    Oleg
    Participant

    Hi Dominic,

    Great idea! I know about this JSF 2 feature, but I did only think about URL-rewritng.

    Thank you a lot.

    #20248

    Oleg
    Participant

    Hi,

    No, it’s not what I wish me. I have now links like

    <link type=”text/css” rel=”stylesheet” href=”/icManagement/javax.faces.resource/ip-jsftoolkit.jsf?ln=js&v=20101014184544_0″>

    v=20101014184544_0 is not the part of URL. It’s in the query string. Such URLs are sometimes not cached at all (if e.g. tomcat with apache). I want to cache resources until the version is the same. This is my intention.

    #20249

    Have you considered enabling this caching at the browser level?

    http://github.com/lincolnthree/ocpsoft-socialpm/blob/master/src/main/java/com/ocpsoft/socialpm/web/filter/ResponseHeaderFilter.java

    http://github.com/lincolnthree/ocpsoft-socialpm/blob/master/src/main/webapp/WEB-INF/web.xml

    This way the unique filename will always be cached by the browser until the expiration date.

    #20250

    domdorn
    Participant

    In production mode, JSF adds appropriate cache headers.

    #20251

    Good to know, thank you.

Viewing 8 posts - 1 through 8 (of 8 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.