Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Created April 15, 2015 14:26
Show Gist options
  • Save zulhfreelancer/f63032cfd8965c3a07cb to your computer and use it in GitHub Desktop.
Save zulhfreelancer/f63032cfd8965c3a07cb to your computer and use it in GitHub Desktop.
Live reload using BrowserSync // http://www.browsersync.io/docs/command-line/
1. Install BrowserSync via NPM:
npm install -g browser-sync
2. Using Terminal, cd into project folder:
Example: cd/test
3. Add this kind of script inside HTML files:
<script type='text/javascript' id="__bs_script__">//<![CDATA[
document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-client.2.6.4.js'><\/script>".replace("HOST", location.hostname));
//]]></script>
Note: Do not change the HOST variable.
4. Run this inside the Terminal:
browser-sync start --files "*.html,css/*.css,js/*.js" --server
Note:
This will watch all HTML, CSS & JS file changes. If only want to watch & live reload HTML, remove "css/*.css,js/*.js" inside the command.
5. Open all browsers and all files will be watched and live reload will take place. Also work on another device using IP address like this: 192.168.X.XXX:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment