-
Notifications
You must be signed in to change notification settings - Fork 74
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
Manually triggering reload? #68
Comments
I don't have any plans to implement something like this currently. Trying to wrap my mind around why you even need to do this. Can you give a lot more background info and be specific about what you'd like to have happen? What part of the API would need to change? |
Sorry I wasn't clear before. Here's the folder structure i use for my node app.
I'd go ahead and use this library as nodemon.on('restart', function() {
setTimeout(function() {
livereload.refresh();
}, 3000);
}); I couldn't figure out how to modify the existing code but it seems the |
@harshithkashyap very helpful. Let me dig in. |
@harshithkashyap Can you try v0.5.0 with the delay ( |
@napcs Thank you for the new version. From the v0.5 i see two approaches to use the delay.
|
Reopen if this isn't a workable solution. |
I have the same problem. I have client-side files and server-side files. When I change client-side files, LiveReload can refresh my browser immediately. When I change server-side files, nodemon restarts my server, and only after the server has restarted can the browser be refreshed. In my opinion, the right solution to this is for nodemon to start my server which starts a livereload server that only watches the client-side files. To get a refresh when server-side files are changed, it's a simple matter of telling livereload to trigger a refresh of the browser, after my server has started. Unfortunately, there appears to be no way to do this. Using a hardcoded delay seems like a hacky workaround. It also won't work well because my server startup time might change due to network conditions. I found #79 (comment), but it seems like what you said there would not be a problem for the setup I'm proposing. I'm not saying that livereload should reload on initial connection, but rather when I explicitly request it. What am I missing here? |
As an addendum, I found that using |
The So you'll have to figure out the right solution for your app. I'd try to find something better than nodemon - it seems overkill to have to bounce the whole server every time you make a change to a file. LiveReload literally just watches files that change. It'll watch any file extension you tell it to watch and it will send the appropriate refresh command. Just tell LiveReload. I just ran a simple test of all this with a basic Express app:
Then in a new window, I started the LiveReload CLI to watch
The output shows it's watching:
So then I make an edit to And LiveReload sees it:
Of course, it reloaded the page, which disconnected the browser, which then reconnected. So this is working as expected. But the page in the browser immediately reflected the changes. So the Express app lets me change the pug views without bouncing the server. Next I went and changed something in the routes that affects the views. I changed:
to
Saved, and of course, LiveReload noticed there was a file change, but didn't update the HTML, cos it's a server-side JS file. :) Also, of course the server needed a bounce to make the change take effect. So I restarted the server. And, as expected, the change didn't take effect on the web page. But a manual refresh fixed everything right up. So did a change to a pug file. I''m thinking you could probably do this as the safest workaround if you can't / won't move off of Nodemon:
and it would work ok. |
Thanks, the suggestion about using LiveReload to update Pug files without restarting the server is really cool. However, I really do want restarting the server to cause a refresh in the browser. From my understanding, the problem appears to be that LiveReload can't directly tell the client to refresh, it can only tell the client which file was updated. This seems like a shortcoming in the protocol to me, but I guess it can't be fixed here. That said, an Express server using Pug is not serving static assets. So there's really no way for the client to draw a link between the Pug file that was updated, and the current page that's being viewed. I can only assume that whenever the client gets a message about any Pug file being updated, it refreshes. So in essence, LiveReload does have a way of forcing the client to refresh. Would it make sense for LiveReload to expose a method to explicitly perform this functionality? Are there complications that make it more difficult to implement than I am thinking? (After all, touching a JavaScript file that I know is used on all pages in my application does appear to work, but it's difficult to get a hack like that past code review :P) |
The reason Pug stuff works is the default behavior refreshes the existing page. But the method on the client that requires that requires a path and some options. I have to maintain compatibility with the CLI, the official browser plugin, and the browser extension. And I can't change the code for the client-side pieces. You can certainly hack it, but there's no guarantee it won't change later. Try
And see if that works. If it does, let me know. |
Firstly, I'm sorry for the delay in my response (this is a work project). Secondly, your suggestion works perfectly. In my case, I would actually not use a timeout, and instead call I think it's a shortcoming in the LiveReload client protocol that there's no way to just tell the client to refresh the page, but it does indeed appear that sending an empty string for the path is a valid workaround, at least for some client implementations. Thanks for your help. This is a really helpful tool. |
Great to hear it works. I might go implement a |
hey all
might work better! found solution to my case here https://bytearcher.com/articles/refresh-changes-browser-express-livereload-nodemon/ |
nodemon app takes a few seconds to restart the server but the live reload is triggered as soon as a file is changed. Is there a way to manually trigger the reload? I'm trying to use the nodemon restart event and manually trigger a reload(Not watching server files). Client files would be handled via args.
The text was updated successfully, but these errors were encountered: