I am trying to force the browser to cache the static resources like Javascript and image files. I try to use a Servlet filter to achieve this by setting "Expires" response header when one of these resources is requested.
But, the response headers set by my Servlet filter is simply ignored and it seems the server is setting a default value for "Expires" response header.
When I test in my local machine the "Expires" header is set to 7 days ahead, but my production server sets this as only 10 minutes ahead!
How can I set the "Expires" header to my desired value?
How to make the browser to cache the static resources?
Is there any chance somebody has figured this out?
My Expires header is actually set to the same second as the response causing there to be no caching at all.
This is causing the jQuery script to be loaded on every page request. I enabled compression in Glassfish which took the script size from 200K to 50K, but still, there has to be a way to set the Expires header.
My Expires header is actually set to the same second as the response causing there to be no caching at all.
This is causing the jQuery script to be loaded on every page request. I enabled compression in Glassfish which took the script size from 200K to 50K, but still, there has to be a way to set the Expires header.
I found the answer to my own question.
If javax.faces.PROJECT_STAGE in your web.xml is set to Development, it automatically sets it to not cache (expires=current time).
If it is set you Production, it sets it to 10 mins.
You can override the 10 mins by adding another context paremeter: com.sun.faces.defaultResourceMaxAge
The default of this is 604800 which is ~10mins.
Hope this helps somebody else. No servlet filters needed.
If javax.faces.PROJECT_STAGE in your web.xml is set to Development, it automatically sets it to not cache (expires=current time).
If it is set you Production, it sets it to 10 mins.
You can override the 10 mins by adding another context paremeter: com.sun.faces.defaultResourceMaxAge
The default of this is 604800 which is ~10mins.
Hope this helps somebody else. No servlet filters needed.
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Thanks for sharing.
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
probably the best way is to implement an own servletfilter for caching
Thomas Andraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
http://ovaraksin.blogspot.com/2011/02/i ... ustom.html
Might help as well for invalidating when you update, I haven't used it though.
Might help as well for invalidating when you update, I haven't used it though.
Thanks Cagatay,
I posted what we implemented recently in our web app and it's working of course.
I posted what we implemented recently in our web app and it's working of course.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
-
- Information
-
Who is online
Users browsing this forum: No registered users and 36 guests