2

I downloaded the community edition of Broadleaf and I'm trying to change some markup in the Thymeleaf templates. (For example: layout/homepage.html). However, when I make a change, I don't see my changes when I refresh my browser unless I restart my Broadleaf site server. I have the same issue when editing JS and CSS.

Is there a setting that needs to be changed to see frontend changes without restarting the server? I'm suspecting some sort of cache setting is preventing the templates from reloading from the file.

jthomas
  • 1,162
  • 1
  • 11
  • 19
  • According to an old forum post, it looks like there is a cache setting for this. Setting cache.page.templates should prevent the templates from caching. The developers say they use JRebel for hot-deploys, so they don't rely on the cache setting. http://forum.broadleafcommerce.org/viewtopic.php?t=1565 – jthomas Nov 02 '18 at 19:07

4 Answers4

2

Sorry for the misleading forum post. The cache settings he's referring to doesn't alleviate the problem you're having. Without Jrebel or some sort of hotswapping mechanism you will not be able to see changes without restarting the server. One thing that might work is if you run the project from your IDE the template changes might show because it may place your changed templates into the Jar that is deployed.

After a google search I did run across this as well https://blog.codeleak.pl/2016/12/thymeleaf-reload-templates-and-static-resources.html. I'm not sure if it works but it's worth a try

pequals
  • 91
  • 6
  • 1
    Ok, we'll try some of that. Our backend guys have JRebel, but not the frontend guys. We came across that article as well, so we may tinker with that approach before purchasing JRebel. We'll report back with what we find. – jthomas Nov 05 '18 at 14:32
  • 1
    We had some success with getting templates to change without JRebel if we check the box in IntelliJ settings called "Build Project Automatically" (under the Build... -> Compiler settings). The only caveat is that you can't run the project in your IDE. You have to run it in a separate terminal. – jthomas Nov 07 '18 at 17:02
  • That's really interesting. Thank you for the update. For additional assistance with Broadleaf you can also post on our public Gitter here https://gitter.im/BroadleafCommerce/BroadleafCommerce. We monitor both StackOverflow and our Gitter. – pequals Nov 08 '18 at 00:54
  • 1
    It also works in eclipse/STS with build automatically enabled. – Marquee Nov 08 '18 at 19:28
1

Using the IDE rebuild seems to work with the oob Breadleaf Demo Site when running from a terminal with the spring-boot maven goal:

mvn spring-boot:run

Once it is running, if you update the templates/css inside the IDE with build automatically enabled (important!), then the site does reflect the changes upon refresh.

I verified this works with IntelliJ, Spring Tool Suite, and base Eclipse.

Marquee
  • 1,776
  • 20
  • 21
  • This worked for me as long as I'm not running the project in my IntelliJ IDE. It sounds like I'd have to use something like JRebel if I want to run Broadleaf in the IDE. – jthomas Nov 09 '18 at 17:01
0

With Broadleaf 6.0.6, I had to add template resolver bean:

@Bean
public BroadleafTemplateResolver devTemplateResolver() {
    BroadleafThemeAwareTemplateResolver resolver = new BroadleafThemeAwareTemplateResolver();
    resolver.setPrefix(Paths.get("src/main/resources/").toUri().toString());
    resolver.setTemplateFolder("webTemplates/");
    resolver.setSuffix(".html");
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCacheable(false);
    resolver.setOrder(10);
    return resolver;
}

That is a "Demo Site" project, SiteConfig.java class.

This bean goes to the top of the list of template resolvers, so chnages to the template files are picked up form src folder, no need to re-build.

Dario
  • 43
  • 4
0

add needs to be done is to disable catching for the template in Thymeleaf. add this to your application properties file.

spring.thymeleaf.cache=false
majed
  • 467
  • 4
  • 7