Caching static PF resources problem

UI Components for JSF
User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

29 Dec 2010, 18:29

Caching static resources is a recommended way to make web pages load quickly. If I cache static Primefaces resources (both on users machines and on proxies), how can I upgrade to a new version of PF?
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

smallya
Posts: 264
Joined: 19 Mar 2010, 19:22
Contact:

30 Dec 2010, 06:05

MISS_DUKE,
The standard way to cache static resources like CSS or JS files is to label them with a version number like this

http://static.yourwebsite.com/css/style.css?v=1234

Assuming that you have set directives to cache the static resources in your .htaccess the browser will cache them. One way is to set expiry on them to say 60days or 30 days depending on your release schedule.

If you want to force invalidation of that cached resource and force browsers to download the new version, increment the version number as part of the next release deployment like this

http://static.yourwebsite.com/css/style.css?v=1235.

Browsers will see the change and request the new version. You can do the same with images. You can suffix the images with a version number like logo_<versionnumber>.png and keep incrementing that.

Hope this helps.
Netbeans 7.2| GlassFish 3.2 | PostgreSQL 9.1| MongoDB | Primefaces 3.4.2
_______________________________________________________________
Subraya Mallya
http://tinyhabit.com |http://twitter.com/tinyhabit

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

30 Dec 2010, 06:15

Adding version number to a static resource is really good idea.

But this idea cannot be implemented with Primefaces because Primefaces automatically creating static contents, for example:

Code: Select all

/faces/javax.faces.resource/yui/utilities/utilities.js?ln=primefaces
The URL for "utilities.js" will be the same in all Primefaces versions.
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

30 Dec 2010, 12:09

Starting with 2.2.RC2, resource url has the version information like;

Code: Select all

<script type="text/javascript" src="/showcase/javax.faces.resource/yui/utilities/utilities.js.jsf?ln=primefaces&v=2.2.RC2"></script>

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

30 Dec 2010, 12:25

Really good news to hear. This is a must have feature. Thank you.
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
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

08 Jan 2011, 03:40

But JSF (Mojarra 2.0.3) resources are not given any version numbers, for example:

/faces/javax.faces.resource/jsf.js?ln=javax.faces

So, what happens when we upgrade to next Mojarra version (when it is released) ?
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

smallya
Posts: 264
Joined: 19 Mar 2010, 19:22
Contact:

25 Jan 2011, 04:13

Besides logging this issue with the Mojarra team, in the interim, you can add directives in .htaccess for the site to control this.

Expiry setting

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 31 Mar 2011 20:00:00 GMT"
</FilesMatch>

and Cache Control

# value in seconds
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
Netbeans 7.2| GlassFish 3.2 | PostgreSQL 9.1| MongoDB | Primefaces 3.4.2
_______________________________________________________________
Subraya Mallya
http://tinyhabit.com |http://twitter.com/tinyhabit

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

25 Jan 2011, 04:20

I think you are talking about Apache but we are using Glassfish.
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

smallya
Posts: 264
Joined: 19 Mar 2010, 19:22
Contact:

26 Jan 2011, 22:38

Missed that - here is something I had in my archive http://blogs.sun.com/cwebster/entry/cac ... _glassfish although I have not tried it myself yet.
Netbeans 7.2| GlassFish 3.2 | PostgreSQL 9.1| MongoDB | Primefaces 3.4.2
_______________________________________________________________
Subraya Mallya
http://tinyhabit.com |http://twitter.com/tinyhabit


Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 38 guests