question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Template "hot reload"

See original GitHub issue

I’m testing a dummy template as follows:

.get("/test", ctx -> ctx.render("templates/test.mustache", new HashMap<>()));

Editing the template (test.mustache) requires restarting the app (or maybe rebuilding the app, but stop + run in Eclipse anyway).

It’s a major use case to be able to work with a template without a need of restarting the Javalin app for every change. I even tried to add .enableStaticFiles(“src/resources/templates”, Location.EXTERNAL), but no luck.

Is this a feature? Works differently in SparkJava by the way.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tipsycommented, Dec 10, 2018

Happy you found a solution @valtterip!

Gotta be done for every request, so obviously for development purposes only, but I’m fine with this now.

Instead of doing it “manually” per request, you could register a new FileRenderer:

JavalinRenderer.register((filePath, model) -> {
    MustacheFactory mustacheFactory = new DefaultMustacheFactory("./");
    StringWriter stringWriter = new StringWriter();
    mustacheFactory.compile(filePath).execute(stringWriter, model).close();
    return stringWriter.toString();
 )}, ".mustache")

Then you could use Javalin like normal, with calls to ctx.render(...).

Some sort of reload-on-modify -option would be cool

I don’t think anything template-specific should be included in Javalin, other than a minimal example implementation that can be overridden by the user.

1reaction
tipsycommented, Feb 13, 2020

I don’t think this belongs in Javalin, tbh.

I agree, but thank you for documenting your solution here. I’ve added the info tag.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sample app that demonstrates enabling hot reload for Marko ...
Marko Sample - Hot Reloading. Marko provides a hot-reloading feature that allows templates to automatically be reloaded without a restart.
Read more >
Reload Flask app when template file changes - Stack Overflow
To reload your application when the templates change (or any other file), you can pass the extra_files argument to Flask().run() , a collection...
Read more >
84. Hot swapping - Spring
There are several options for hot reloading. ... They will, however, trigger a live reload. ... 84.2 Reload templates without restarting the container....
Read more >
Hot Reload ignoring DataTemplate change
To repeat the problem run the enclosed application, click edit mode, then click insert text, then select new text, click add animation, fade...
Read more >
handlebars-hot-reload - npm
This CLI aims to render handlebar templates with hot reload functionality for ease of development of handlebar templates.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found