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

Option to reload or prevent caching of templates #163

Closed
trombonehero opened this issue Jan 30, 2017 · 10 comments
Closed

Option to reload or prevent caching of templates #163

trombonehero opened this issue Jan 30, 2017 · 10 comments
Labels
accepted An accepted request or suggestion request Request for new functionality

Comments

@trombonehero
Copy link

It would be super-helpful for development and debugging if Rocket could reload cached templates when I modify them, or else turn off caching altogether in development mode.

@trombonehero trombonehero changed the title Option to reload or prevent caching templates Option to reload or prevent caching of templates Jan 30, 2017
@SergioBenitez SergioBenitez added the request Request for new functionality label Jan 30, 2017
@SergioBenitez
Copy link
Member

SergioBenitez commented Jan 31, 2017

I've handled this same issue out-of-band by using tools like entr or watchexec. These tools monitor some set of files and run a command when any of those files changes. For instance, you can ask watchexec to monitor template files and restart the application on changes with:

watchexec --exts tera,hbs --restart "cargo run"

Unless the template engines themselves support the feature (which they presently don't), I think adding this functionality to Rocket isn't a great idea. The complexity isn't worth the reward, in my opinion, especially when it's so easy to use an out-of-band tool.

@mehcode
Copy link
Contributor

mehcode commented Jan 31, 2017

https://github.com/passcod/cargo-watch looks promising. It doesn't support running a server yet but it's on the top of their roadmap.

@trombonehero
Copy link
Author

Ok, that's fair enough. In fact, the watchexec approach is even better than reloading templates because it can also reload on .rs file changes.

Now the only remaining question is, what would be required to integrate LiveReload-like functionality (á la http://nitoyon.github.io/livereloadx) to Rocket? If Rocket told my web page to reload itself every time it started running again after watchexec-driven recompilation... well, that would be nice.

@SergioBenitez
Copy link
Member

I use the LiveReload application for exactly that, @trombonehero, no changes to Rocket needed. I simply monitor the directory where my application is, and LiveReload does the rest.

@SergioBenitez
Copy link
Member

@trombonehero Do you still feel like this is something Rocket should have built-in?

@trombonehero
Copy link
Author

I have found that the built-in LiveReload functionality of Hugo (https://gohugo.io) is quite useful because it's embedded directly in the HTML and doesn't require any extra browser support. For example, I can use livereloadx on my Mac, but on FreeBSD the Firefox plugin isn't supported, whereas the in-page functionality of Hugo works just fine. However, I can see how this sort of thing would have a pretty low priority in terms of wishlist.

As for the original request, I think your response is entirely reasonable. It's even more compelling since I've started playing around with Maud, where the template is Rust code. So, I wouldn't at all object to this issue being closed if that seems like a good way to handle it to you.

@SergioBenitez
Copy link
Member

For now, I think this is something better handled outside of Rocket. Maybe one day we'll have a rocket CLI, and rocket watch will do the right thing. ;)

Closing this issue for now.

@SergioBenitez SergioBenitez added the declined A declined request or suggestion label Feb 9, 2017
@Qqwy
Copy link

Qqwy commented May 19, 2017

For templating specifically, I think it would be nice if Rocket could reload templates automatically during development. Further, I think it's absolutely possible, and quite simple, in fact, given the new fairings and the new Template implementation in master. We should see this in the not-too-distant future. We can have that discussion in #163.

Maybe it is worth opening this issue again, so we can talk about template reloading in more detail :-).

@SergioBenitez SergioBenitez reopened this May 19, 2017
@SergioBenitez SergioBenitez removed the declined A declined request or suggestion label Jun 11, 2017
@Cxarli
Copy link

Cxarli commented Oct 11, 2017

I'd like to bump this. Would it be possible to re-parse a template every time a request is made (optional, developing environment). I think restarting the server every time one changes a little HTML shouldn't be necessary

@jebrosen
Copy link
Collaborator

I am working on this issue now, informed by #523 (comment). I am to a point where the template context is reloaded on every request made in debug mode, including re-running the engine customization callback. The next step is to reload only when files were actually changed on disk; after that is done I will focus on cleaning up some rough edges and submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted An accepted request or suggestion request Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants