Message Boards

Local deploy of theme requires Tomcat restart

Jeff Hellman, modified 4 Years ago.

Local deploy of theme requires Tomcat restart

New Member Posts: 11 Join Date: 7/11/19 Recent Posts
When doing local development of my theme, the "gulp deploy" task appears to successfully deploy my theme .war to the local Tomcat instance, and indeed I can immediately see changes I make to the Freemarker templates. However, the main.css delivered to the browser doesn't have the most recent changes.

I can see in the .war that is deployed that the main.css does have my changes. It would appear that Tomcat keeps a cached version of that main.css file in  the following location (for example):


...\liferay-dxp-7.2.10-ga1\tomcat-9.0.17\work\Catalina\localhost\ROOT\css\http__o_theme-name_css_main.css....

Is there a recommendation on how to clear that cache as part of the "gulp deploy"? I could do it manually but I'd prefer not to. I could also restart Tomcat each time I deploy but I want to do that even less than manually deleting the cache.
Patrick Yeo, modified 4 Years ago.

RE: Local deploy of theme requires Tomcat restart

Junior Member Posts: 61 Join Date: 2/8/13 Recent Posts
https://portal.liferay.dev/docs/7-2/frameworks/-/knowledge_base/f/using-developer-mode-with-themes
Put portal-ext.properties in the ...\liferay-dxp-7.2.10-ga1 directory and restart server. It should disable caching.
Jeff Hellman, modified 4 Years ago.

RE: Local deploy of theme requires Tomcat restart

New Member Posts: 11 Join Date: 7/11/19 Recent Posts
I added the portal-ext.properties to no effect unfortunately. The behavior is interesting, the following scenario plays out:
  1. Launch local Tomcat
  2. Load page in Chrome - see page load as expected
  3. Make a change to the theme and run "gulp deploy"
  4. Confirm the .war is deployed to Tomcat and see the "STARTED" message from the Bundle Listener
  5. Do a hard refresh/clear cache in Chrome, do not see the theme change
  6. Load page in Edge - see page load WITH the theme change
  7. Make another change to the theme and run "gulp deploy"
  8. Confirm the .war is deployed to Tomcat (same as before)
  9. Do a hard refresh/clear cache in Edge and Chrome, do not see the theme change in either browser
  10. Load page in Internet Explorer 11 - see page load WITH the first and second theme changes
  11. Do the same theme change/redeploy steps (#3 and #4) and see no change in Chrome/Edge/IE 11
So this baffles me because if it was a browser cache issue then loading the page after clearing the cache and restarting the browser would address that. If it was a server cache issue, then I would think the browsers would receive the same .css file served up from Tomcat.
  • Does Tomcat keep track of what browser it has served content up to and cache it specifically that way?
  • Is there something in the .css file URL or HTTP request headers that changes behavior on Tomcat for what it serves up?
  • Does using DXP instead of CE for the Liferay version make a different in the developer properties I tried?
Jeff Hellman, modified 4 Years ago.

RE: Local deploy of theme requires Tomcat restart

New Member Posts: 11 Join Date: 7/11/19 Recent Posts
I am less baffled about the browser difference now, it looks like the requested URL does change with a browserId parameter, which in turn results in a new set of files in the Tomcat cache location:

C:\Liferay\liferay-dxp-7.2.10-ga1\tomcat-9.0.17\work\Catalina\localhost\ROOT\css


So now at least I understand why switching browsers works the first time, at which point point it will add the cache files and then subsequent requests with that browser get served those. So it's still a matter of server caching at this point.
thumbnail
Marco Endres, modified 3 Years ago.

RE: Local deploy of theme requires Tomcat restart

Regular Member Posts: 112 Join Date: 8/22/12 Recent Posts
I have sometimes the same problem. Did you find out more? Do yu know how I can clean those files without going to delete those files by hand?Marco
Jeff Hellman, modified 3 Years ago.

RE: Local deploy of theme requires Tomcat restart

New Member Posts: 11 Join Date: 7/11/19 Recent Posts
I ended up doing it by hand in an automated and slightly brittle fashion. I created a gulp task in my theme project and bound it to the deploy task from the existing liferay-theme-tasks  - - code is as follows. You'll need to update your path accordingly, and this is the brittle piece since any changes to folder structure and this breaks. 


var&nbsp;cachePath&nbsp;=&nbsp;'C:/<path to your tomcat instance>/tomcat-9.0.17/work/Catalina/localhost/ROOT/css/';
var&nbsp;cacheFilePattern&nbsp;=&nbsp;"*liferay-federated-client-portal-theme*";

gulp.task('deploy:clean-cache',&nbsp;['deploy'],&nbsp;function&nbsp;()&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;force&nbsp;the&nbsp;delete&nbsp;since&nbsp;this&nbsp;is&nbsp;outside&nbsp;the&nbsp;working&nbsp;directory&nbsp;and&nbsp;below
&nbsp;&nbsp;&nbsp;&nbsp;del(cachePath&nbsp;+&nbsp;cacheFilePattern,&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;force:&nbsp;true
&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;log("Cached&nbsp;CSS&nbsp;has&nbsp;been&nbsp;deleted&nbsp;from:&nbsp;"&nbsp;+&nbsp;cachePath&nbsp;+&nbsp;cacheFilePattern);
});
</path>
thumbnail
Marco Endres, modified 3 Years ago.

RE: Local deploy of theme requires Tomcat restart

Regular Member Posts: 112 Join Date: 8/22/12 Recent Posts
Thank you very much. This could be really useful next time emoticon
Jeff Hellman, modified 3 Years ago.

RE: Local deploy of theme requires Tomcat restart

New Member Posts: 11 Join Date: 7/11/19 Recent Posts
Honestly, I just got in the habit of running `gulp deploy:clean-cache` instead of the regular `gulp deploy` and figured I never cared whether the cache was still there emoticon
thumbnail
Marco Endres, modified 3 Years ago.

RE: Local deploy of theme requires Tomcat restart

Regular Member Posts: 112 Join Date: 8/22/12 Recent Posts
Do you also had the problems on test or prod-environments? Where you only deploy the .war?
thumbnail
Milan Riha, modified 3 Years ago.

RE: Local deploy of theme requires Tomcat restart

New Member Posts: 6 Join Date: 8/9/08 Recent Posts
Hi,what work for me in LR 7.3 is change theme version in package.json and make any change directly in main.scss file, even if not needed. For example when I change only imported file.
thumbnail
Marco Endres, modified 3 Years ago.

RE: Local deploy of theme requires Tomcat restart

Regular Member Posts: 112 Join Date: 8/22/12 Recent Posts

Maybe it helps somebody :)

https://github.com/liferay/liferay-frontend-projects/issues/402