2

What is the best way to get auto-reloading to work when developing my website (my website runs on Mojolicious)?

There exists a development server called morbo, and it does update what is served automatically whenever I save changes to a source file, but the website itself does not reload automatically. I must manually refresh the page to see the changes.

What is a sane way to get this behavior? I am okay with using an additional tool if necessary.

mareoraft
  • 3,474
  • 4
  • 26
  • 62
  • 1
    Can you elaborate on "the website itself does not reload"? What are you expecting to happen and what actually happens? Do you want the client to automatically show new results? What other servers are you using besides more? – brian d foy Dec 29 '20 at 15:52
  • @briandfoy I added some clarifying details to the question. Yes, I do want the client to automatically show the new results. Besides `morbo`, I have experimented with other servers such as the builtin one and `hypnotoad`. You can also read wsdookadr's answer and the [Mojolicious::Plugin::AutoReload](https://metacpan.org/pod/Mojolicious::Plugin::AutoReload) webpage for further description of what I mean by "auto-reload" (I previously wrote "hot-reload" but I have now changed it to "auto-reload"). The question is now answered so I do not need further help. Thank you! – mareoraft Dec 29 '20 at 23:51
  • 1
    Not sure why the 2 downvotes (and the 2 close-votes). This question and the answer could be useful to anyone who uses Mojolicious. The question is clear (for anyone who has experience with Mojolicious). Personally, I learnt something that I'll probably use in the future. – Dada Dec 30 '20 at 13:48

1 Answers1

3

My understanding is that Mojolicious::Plugin::AutoReload can do what you want by defining a auto_reload endpoint and having the UI poll your web app to check if the UI should reload.

The module was featured on the Mojolicious blog in 2018.

wsdookadr
  • 2,584
  • 1
  • 21
  • 44
  • Running `cpan install Mojolicious::Plugin::AutoReload` in the terminal and adding the line `plugin AutoReload => {};` immediately below `use Mojolicious::Lite;` was enough to make it work. I have verified it works in Safari and Firefox on macOS, and on Google Chrome on Windows 10, using the `perl:5.32-slim-buster` docker image from [dockerhub](https://hub.docker.com/_/perl) for my backend running morbo. Thank you, this is exactly what I was looking for! – mareoraft Dec 29 '20 at 23:43