DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

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!

Praveen N user avatar by
Praveen N
·
Jun. 11, 17 · Tutorial
Like (2)
Save
Tweet
Share
6.82K Views

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.

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.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How Do the Docker Client and Docker Servers Work?
  • Tech Layoffs [Comic]
  • Using JSON Web Encryption (JWE)
  • Remote Debugging Dangers and Pitfalls

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: