Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload current page upon code changes with Livereload #19

Closed
BjoernKW opened this issue Dec 22, 2022 · 8 comments
Closed

Reload current page upon code changes with Livereload #19

BjoernKW opened this issue Dec 22, 2022 · 8 comments
Labels
command: run type: enhancement New feature or request
Milestone

Comments

@BjoernKW
Copy link

BjoernKW commented Dec 22, 2022

If the Spring Boot application started via just run is a web application (or, more specifically: a web application providing HTML views), Just could launch the default browser with the web application's home page (usually http://localhost:8080) and reload the current page in the browser upon code changes.

While the former (launching a browser from the command line) probably is rather easy, the latter (i.e. live reloading changes) would require a more sophisticated approach, like the live reload servers provided by web frameworks such as Angular or React.

@BjoernKW BjoernKW changed the title Live browserrreload Live browser reload Dec 22, 2022
@BjoernKW BjoernKW changed the title Live browser reload Launch browser and reload current page upon code changes Dec 22, 2022
@maciejwalkowiak
Copy link
Owner

I see this for traditional server side rendered applications but I am not sure how this could be solved for SPA projects. I think usually the frontend code is in the separate git repository. And if it is not, how Just would know what to run and when to run? Suggestions are welcome :-) Also if you have a sample repo somewhere with the setup you have in mind I am happy to take a look.

@BjoernKW
Copy link
Author

BjoernKW commented Dec 22, 2022

I see this for traditional server side rendered applications but I am not sure how this could be solved for SPA projects. I think usually the frontend code is in the separate git repository. And if it is not, how Just would know what to run and when

I was specifically thinking about server-side rendering; Thymeleaf, in particular. Like you said, for SPA front-ends that feature is pretty much covered already, for server-side rendering live reloading support for Java applications for the most part is still lacking or involves awkward workarounds with browser extensions.

to run? Suggestions are welcome :-) Also if you have a sample repo somewhere with the setup you have in mind I am happy to take a look.

Sure. Using Wim Deblauwe's Taming Thymeleaf CLI (which is amazing in its own right, by the way) I've created a sample project which shows the behaviour I have in mind (the README.md file contains the required steps for launching the application in live reload mode): https://github.com/BjoernKW/thymeleaf-live-reloading-demo

In a nutshell, just run would have to run an npm run watch command, which in turn would launch a Browsersync instance for implementing the desired behaviour.

@maciejwalkowiak
Copy link
Owner

Thanks a lot! If I understand it right - it essentially means having live reload of static resources/templates without installing an extension http://livereload.com/extensions/ ..?

@BjoernKW
Copy link
Author

Thanks a lot! If I understand it right - it essentially means having live reload of static resources/templates without installing an extension http://livereload.com/extensions/ ..?

Yes, that's it exactly! This makes the project's development setup self-contained and the project ready to be used out-of-the-box.

@BjoernKW
Copy link
Author

BjoernKW commented Dec 22, 2022

Thanks a lot! If I understand it right - it essentially means having live reload of static resources/templates without installing an extension http://livereload.com/extensions/ ..?

Besides, with the last update having been made 7 years ago, LiveReload Browser Extensions probably is hopelessly outdated. Their website isn't even available anymore, which really has me wonder why it's still mentioned as a viable solution in the current Spring Boot documentation (https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools.livereload), but that's another matter and one Spring Boot core developers probably should have a look at ;-)

Edit: See this issue spring-projects/spring-boot#32111

@maciejwalkowiak
Copy link
Owner

Thanks @BjoernKW! Got it working in Just 🚀

@maciejwalkowiak maciejwalkowiak added this to the 0.13.0 milestone Dec 22, 2022
@maciejwalkowiak
Copy link
Owner

Because of the dependency on servlet related classes I will make it work for Spring Boot 3.0+

@maciejwalkowiak maciejwalkowiak changed the title Launch browser and reload current page upon code changes Reload current page upon code changes with Livereload Jan 10, 2023
@maciejwalkowiak
Copy link
Owner

Managed to get it working for both Spring Boot 2.7+ and 3.0+. Only refreshing part. I am not sure if opening browser is the right way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command: run type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants