Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Browsersync With Any Server and Custom File Watcher Without Proxy

DZone's Guide to

Using Browsersync With Any Server and Custom File Watcher Without Proxy

Learn how to install this free JavaScript library, and start optimizing the performance of your web application of site. Read on for more!

· Web Dev Zone
Free Resource

Get the senior executive’s handbook of important trends, tips, and strategies to compete and win in the digital economy.

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.

Pre-requisites :

Node.js and npm.

Installing browser-sync:

Use the following command to install browser-sync:

npm install -g browser-sync

Starting Browser-sync:

Use the following command to start browser-sync:

browser-sync start

Adding browser-sync-client.js:

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>

Almost Done:

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:

browser-sync reload

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.

Read this guide to learn everything you need to know about RPA, and how it can help you manage and automate your processes.

Topics:
web dev ,javascript library ,browsersync

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}