Using Browsersync With Any Server and Custom File Watcher Without Proxy
Join the DZone community and get the full member experience.Join For Free
Browser-sync is one of the most used libraries for live reloading of a web page. It helps the developer a lot. If you want to know more about browse-sync visit this page.
Browser sync by default uses a node server to host your file.
I am going to show you how to setup browser sync with any server and custom file watcher.
Node.js and npm.
Use the following command to install browser-sync:
npm install -g browser-sync
Use the following command to start browser-sync:
Now add the following code inside the <body> tag of all your HTML file.
<script id="__bs_script__">//<![CDATA[ document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-client.js?v=2.18.12'><\/script>".replace("HOST", location.hostname)); //]]></script>
Now access your web application through any browser. You will get the notification 'Browser-Sync connected' on your web page.
Now open the command prompt and enter the following command:
Now the magic happens, your web page will automatically reload in your server.
That's it, you are done. You can find many blogs for writing file watchers in any programming language. The only thing you need to do is to execute the command
browser-sync reload from your file watcher program.
And always, thanks for reading.
Opinions expressed by DZone contributors are their own.