What is browser-sync?
Browser-sync is a powerful tool for web developers that provides live reloading, synchronized browser testing, and other features to streamline the development process. It helps in creating a seamless development experience by automatically refreshing the browser whenever files are changed, and it can also synchronize interactions across multiple devices.
What are browser-sync's main functionalities?
Live Reloading
This feature allows the browser to automatically reload whenever files in the specified directory are changed. The code sample sets up a server to serve files from the 'app' directory and watches for changes in any files within that directory, triggering a reload when changes are detected.
const browserSync = require('browser-sync').create();
browserSync.init({
server: './app'
});
browserSync.watch('app/**/*.*').on('change', browserSync.reload);
Synchronized Browsing
Synchronized browsing ensures that interactions like clicks and scrolls are mirrored across all connected devices. The code sample initializes Browser-sync with ghost mode enabled for clicks and scrolls, allowing these interactions to be synchronized.
const browserSync = require('browser-sync').create();
browserSync.init({
server: './app',
ghostMode: {
clicks: true,
scroll: true
}
});
Proxying an Existing Server
This feature allows Browser-sync to act as a proxy for an existing server, enabling live reloading and synchronized browsing without changing the server configuration. The code sample sets up Browser-sync to proxy requests to 'yourlocal.dev'.
const browserSync = require('browser-sync').create();
browserSync.init({
proxy: 'yourlocal.dev'
});
Other packages similar to browser-sync
live-server
Live-server is a simple development HTTP server with live reload capability. It is easier to set up compared to Browser-sync but offers fewer features. It is ideal for quick prototyping and small projects.
webpack-dev-server
Webpack-dev-server is a development server that provides live reloading and HMR (Hot Module Replacement) for projects using Webpack. It is more complex to set up but integrates deeply with the Webpack build process, making it suitable for larger projects with complex build requirements.
gulp-connect
Gulp-connect is a plugin for Gulp that provides a web server with live reload capability. It is useful for projects that already use Gulp for task automation, offering a seamless way to add live reloading to the development workflow.
browser-sync
Keep multiple browsers & devices in sync when building websites.
Follow @browserSync for news & updates.
##Features
- Scroll - I can keep your pages in sync when scrolling.
- Forms - You fill out a form in one browser, I'll copy the data to all the others.
- Links - I'll watch your clicks and make all the browser follow you.
- CSS injecting - I can even watch your CSS files & inject them when they change.
- Live Reload - I can also watch files like HTML and PHP & when they change I can reload all browsers for you.
- Built-in Server - Yep, I can serve static files too if you need me to
- Use with any back-end setup - Browser-sync includes a proxy option so that it can be used with any existing PHP, Rails, Python, Node or ASP.net setup.
##When is it useful?
It's pretty useful when used with a single browser, watching a CSS file for changes & injecting it. But the real power comes when you're building responsive sites and using multiple devices/monitors because it can keep all browsers in sync & make your workflow much faster.
##Install
Using Grunt? There's a separate plugin for that
npm install -g browser-sync
##How to use it
There are currently 2 ways to use browser-sync - with a config file & without a config file. Both options are explained on the following pages.
- With a config file
- Command line only (no config file)
##Screencasts ( < 3 min each )
- Using the Static Server with css injecting
- Keeping browsers at the same scroll position
- Keeping form fields in sync
- When should you use the built-in server?
+ Laravel (php)
- Browser Sync + Laravel 4 (php server & proxy)
- Browser Sync + Laravel 4 (Mamp Pro & proxy)
- Browser Sync + Laravel 4 (Config file & Proxy)
- Browser Sync + Laravel 4 (Config file & no proxy)
+ Vagrant
- Browser Sync + Vagrant
Want any more? Something specific? ask me nicely @shaneOsbourne
##Support
If you've found Browser-sync useful and would like to contribute to its continued development & support, please feel free to send a donation of any size - it would be greatly appreciated!
#Contributing
Fork this repo, clone it and then run
npm install
###Testing
Tests are split into two categories: Client & Server
Client-side tests
Client-side tests are located in test/client-script/*
// Run the client-side tests & exit
grunt test:client
// Run the client-side tests & re-run on every file-change.
grunt karma:watch
Server-side tests
Server-side tests are located in test/new-server
// Run the server-side tests & exit
grunt test:server
// Run the server-side tests & re-run on every file-change.
grunt watch
// Run the server-side tests & client-side tests once & exit.
grunt test
This is a brand new project so expect bugs & be sure to report them.
License
Copyright (c) 2013 Shane Osbourne
Licensed under the MIT license.