Live reloading (ie File sync) in the web means that the Browser automatically update/refresh the HTML page when you change files in your project (HTML, CSS, images, …)
Reload the page at interval:
<meta http-equiv="refresh" content="10">
setInterval(function(){
window.location.reload();
}, 10000);
The below solution works by injecting code in the page that will open a channel with the server via a web socket. The server will then signal the refresh to the browser.
Application:
Library:
What the basis is of a Live Reload server 1)
var wss = new SocketServer({server})
chokidar
.watch('*.js')
.on('change', path => {
wss.clients.forEach(d => d.send('reload'))
})
new WebSocket(location.origin.replace(/^http/, 'ws'))
.onmessage = () => location.reload()
To enable hot reloading, you need to disable safe write in your IDE. See https://webpack.github.io/docs/webpack-dev-server.html#working-with-editors-ides-supporting-safe-write
“Safe write” means changes are not written directly to original file but to temporary one instead, which is renamed and replaces original file when save operation is completed successfully. This behaviour causes file watcher to lose the track because the original file is removed. In order to prevent this issue, you have to disable “safe write” feature in your editor.