Caching the JavaScript files

UI Components for JSF
primehthb
Posts: 52
Joined: 12 Dec 2010, 22:19

08 Jan 2011, 12:51

Sounds like the very definition of caching to me. At the very least, it is much faster.

Thanks.

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

08 Jan 2011, 12:57

Proper caching should make even faster! Caching is a built in feature in the HTTP protocol itself, we must make full use of it. You may analyze the loading time of your individual resources using Firebug.
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

24 Jan 2011, 18:28

I just started looking at this and here is what I've noticed:

If you want to suggest to client browsers to cache files (and not check the server) then you can use cache-control: max-age (HTTP 1.1) or set expires headers (HTTP 1.0). If you want to set max-age on GlassFish you can use the admin console to configure it. If you want to use expires you can setup a filter. You could do both.

If caching measures aren't taken it appears most browsers will request the resource each time. I've noticed that the GlassFish 3.0.1 with Mojarra 2.2 will return the 304 Not Modified response sometimes even if there really has been changes. This scenario seems to happen on after redeploying an app with stylesheet changes for example. There is still an open question out about how to solve it here: http://stackoverflow.com/questions/2689 ... deployment.

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

24 Jan 2011, 18:50

If you want to set max-age on GlassFish you can use the admin console to configure it.


Please lets know how?

(I guess the "Expires" header can also be configured in the Glassfish server, because, in my project, the "Expires" header takes different values between localhost and the deployment server. But still I could not find how to do so)
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

24 Jan 2011, 18:56

Take a look at the Configuration > Network Config > Network Listeners > http-listener-x then click on File Cache Tab.

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

24 Jan 2011, 19:03

I've also noticed that if you use an h:outputStylesheet component the response will not include an Etag, but if you use a standard HTML link element in your facelet page then the response will include an Etag.

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

25 Jan 2011, 03:30

@bumble.bee
Take a look at the Configuration > Network Config > Network Listeners > http-listener-x then click on File Cache Tab.
I hope the above configuration instructs the server how long to keep the resource in memory, and this is not connected with the browser cache (or the Cache-Control HTTP header) by any means.
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

01 Aug 2011, 19:07

You're right - the File Cache settings are for a GlassFish memory cache so I guess you can't configure caching response headers via the GlassFish admin.

As mentioned in another post If you use PROJECT_STAGE of production then Mojarra will set caching for you, but only for PrimeFaces resources or resources you link via h:outputScript or h:outputStylesheet. There are some resources for which this won't work; for example items which can't go through h:outputStylesheet include a favicon (rel="shortcut icon" type="image/x-icon"), print stylesheets (media="print"), and alternate stylesheets (rel="alternate stylesheet").

However, you can manually invoke the resources sevlet by setting the path to /faces/javax.faces.resource and appending the parameter ln. For example:

This:

Code: Select all

<link type="text/css" rel="stylesheet" media="print" href="#{request.contextPath}/resources/css/print.css"/>
<link type="text/css" rel="alternate stylesheet" media="screen" title="Print Preview" href="#{request.contextPath}/resources/css/printpreview.css"/>
<link type="image/x-icon" rel="shortcut icon"  href="#{request.contextPath}/resources/images/favicon.ico"/>
Becomes this:

Code: Select all

<link type="text/css" rel="stylesheet" media="print" href="#{request.contextPath}/faces/javax.faces.resource/print.css?ln=css"/>
<link type="text/css" rel="alternate stylesheet" media="screen" title="Print Preview" href="#{request.contextPath}/faces/javax.faces.resource/printpreview.css?ln=css"/>
<link type="image/x-icon" rel="shortcut icon"  href="#{request.contextPath}/faces/javax.faces.resource/favicon.ico?ln=images"/>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 46 guests