"How to set Cache-Control headers in Liferay for custom API?" - http-headers

I have written a custom API in Liferay which in cache enabled and working fine on logs(when I hit it the first time it fetches data from database and second time it fetches from webCachePool) but, when I am checking it from browser's network it is not showing any information of cache header (cache-control: private, no-cache, , no-store, must-revalidate)
This is for a new Linux server, running MySQL 5, Liferay 6.2 CE.
I expect the cache-control header like this:
Cache-Control:private, max-age:86400

Liferay sets "Cache-Control" headers in HeaderFilter.java, that filter can be configured in [TOMCAT]/webapps/ROOT/WEB-INF/liferay-web.xml file.
You can modify default "Cache-Control" values or add new ones changing liferay-web.xml values.
(update)
In Liferay Portal 6.2, that configuration only applies to Liferay out-of-the-box functionalities.
If you want to apply it to your own developed Liferay applications, you have also to edit file [tomcat]/webapps/[your-app]/WEB-INF/liferay-web.xml, that file is added by Liferay during application deployment and it is a copy of speed-filters-web.xml that it is inside portal-impl.jar, folder com/liferay/portal/deploy/dependencies.

Related

PWA Caching Issue

I have a PWA which has been developed in ASP.net Core and hosted on an Azure App Service (Linux).
When a new version of the PWA was released, I found that devices failed to update without clearing the browser cache.
To resolve this, I discovered a tag helper called asp-append-version that will clear cache for a specific file. I also discovered that I can append the version of the src attribute that specifies the URL of a file to trigger the browser to retrieve the latest file. For example, src="/scripts/pwa.js?v=1". Each time I update the pwa.js file I would also change the version i.e. v=2.
I’ve now discovered that my PWA is caching other JavaScript files in my application which results in the app not working on devices that have been updated to the new version however failed to clear the cache on specific files.
I believed that if I didn’t specify any cache control headers such as Cache-Control that the browser would not cache any files however this appears not to be the case.
To resolve this issue, is the recommended approach to add the appropriate Cache-Control headers (Cache-Control, Pragma, and Expires) to prevent browser caching or should I only add the tag helper asp-append-version to for example scripts tags to auto clear cache for that specific file?
I would preferably like the browser to store for example images rather than going to the server each time to retrieve these. I believe setting the header Cache-Control: no-cache would work as this would check if the file has changed before retrieving the updated version?
Thanks.
Thanks # SteveSandersonMS for your insights, In your web server returns correct HTTP cache control headers, browsers will know not to re-use cached resources.
Refer here link 1 & link 2 for Cache control headers on Linux app service
For example, if you use the "ASP.NET Core hosted" version of the Blazor WebAssembly template, the server will return Cache-Control: no-cache headers which means the browser will always check with the server whether updated content is present (and this uses etags, so the server will return 304 meaning "keep using your cached content" if nothing has changed since the browser last updated its content).
If you use a different web server or service, you need to configure the web server to return correct caching headers. Blazor WebAssembly can't control or even influence that.
Refer here

My new release not getting browsed in browser post update

I have a website hosted in Apache. its a spring framework application uses angular for front end.
This is being accessed through akamai technology. I have updated the application hosted in the origin server.
When I tried to access from browser it gives a blank page. After doing an 'CTRL + F5' its gives me proper website.
I am not able to sort this out why such behavior in the application. Can any expert in this help me out.
Thanks In advance
Bala
Your page might be cached in your browser. I'd recommend that you could check "cache-control" HTTP response header, e.g.
cache-control: max-age=0, no-cache
It can be controlled by either Akamai or Apache.

dojo app - caching static content such as imgs/css

Im working on and existing dojo application which is requesting the same static content on every page change.
Is there a way to configure the application so this content is cached?.... i.e so every http request has cache control headers?
This is nothing related with Dojo or any other javascript framework.
You can define the cache control configurations either in the Content Server (Apache / Nginx) or in the application server. (if the content is created by the backend server).

jsessionid overridden with tomcat and web-logic as backend servers

For a web-application, we are dependant on CMS deployed on web-logic and web-app deployed on tomcat. When user access a page, dynamic content is rendered from tomcat(sticky session is enabled) and static content(js, css etc.,) are rendered from CMS(on web-logic). This is leading to a conflict on JSESSIONID cookie. The web-logic JSESSIONID is overriding the Tomcat JSESSIONID and the user is loosing the contents saved in session, when moving to and from various parts of the site.
The request flow is as below
[1]: http://i.stack.imgur.com/17Ft5.png
As a band-aid, we wrote a rule on load balancer to drop JSESSIONID for all responses coming from CMS.
Though it worked, looking for a better way to handle this.
Why your CMS is setting a cookie? Does it need sessions to provide those files?
Usually static files do not need a session. One should allow them to be cached on proxies and on the client.
Configure your CMS appropriately. If it is a web application, you may add a Filter that removes Set-Cookie header from its responses (like you are doing on your LB).
It is possible to change the name of a session cookie. This is configurable using <session-config>/<cookie-config>/<name> element in web.xml in web applications that adhere to Servlet 3.0 (or later) specification.
(It is also configurable as sessionCookieName attribute on Context element in META-INF/context.xml, but using web.xml is the recommended way).
Note that Cookies can have a Path attribute. A browser won't send a cookie if its Path does not match the URL of the request. Cookies with Path:/web and Path:/content can happily co-exist together.
Tomcat supports requests that have several JSESSIONID cookies. It just chooses the one that matches an existing session. All the others are ignored.

Force Apache to change http headers from Weblogic

I've configured an Apache in front of a Weblogic. Everything, including static content is stored on Weblogic.
That Apache is configured to set Cache-control max-age and an expiration date HTTP headers of static content when the response comes from Weblogic.
Everything seems to work fine when a user makes the first request of a static content and Weblogic replies with a 200 OK but, once the expiration date is over and browser makes a conditional request, Weblogic replies with a 304 Not Modified BUT that response is not overriden by Apache config so a Cache-Control: max-age=0 arrives to the browser and no new expiration date comes to the browser.
I've seend that I'm unable to set a config to the default weblogic.servlet.FileServlet and, due some development issues, it's impossible to set a custom made Servlet that overrides the default one.
The only option then, is to force Apahe to update the headers of a 304 response from Weblogic.
How can this been achieved?
The problem was related to the configuration of Apache. I had configured the rules related with cache expiration http headers given a mime-type. On a 304 response from Weblogic there is no mime because there is no data so I've updated the rules to take into account the extension of the file types instead mimes and now is working properly