38

I would love to use BrowserSync for development. However, page loading (not only reloading after changes) is extremely slow.

I use the proxy mode. Browsing the page without BrowserSync is fast as it should be.

One reason may be the following error when I install BrowserSync:

> ws@0.4.31 install /usr/local/lib/node_modules/browser-sync/node_modules/socket.io/node_modules/engine.io/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
SOLINK_MODULE(target) Release/bufferutil.node
SOLINK_MODULE(target) Release/bufferutil.node: Finished
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/validation.node
SOLINK_MODULE(target) Release/validation.node: Finished

I installed node from scratch (using brew and the package installer), but couldn't get rid of the error.

Furthermore, it doesn't make a difference if BrowserSync is run using Gulp or over the command line.

Any idea?

Armel Larcier
  • 15,747
  • 7
  • 68
  • 89
Rico Leuthold
  • 1,975
  • 5
  • 34
  • 49

4 Answers4

60

The solution is quite simple - but illogical imho. I had my local instance running under http://project.local. Changing it to http://project.dev solved the issue. I'm running OS X.

Rico Leuthold
  • 1,975
  • 5
  • 34
  • 49
  • 2
    Works. But... but... why? – henrijs Nov 07 '14 at 08:42
  • 13
    :-) If you are running OS X as well, I guess it has something to do with DNS lookups (Bonjour is using the .local domain as well). – Rico Leuthold Nov 07 '14 at 16:01
  • 4
    Amazing tip for mac users. Thanks so much! – Armel Larcier Nov 15 '14 at 16:13
  • 1
    Had the same issue on Linux Ubuntu 14 and changing my URL from 'local.domain.co.uk' to 'domain.dev' worked perfectly! So thank you as never would of solved it otherwise. – JDavies Mar 26 '15 at 11:44
  • This works on Ubuntu 14.10. An explanation as to why a .com slows browserSync down would be nice though. – matthiasdv Jun 11 '15 at 21:10
  • Really insane! I'm on Linux Mint 17.3 and loading a page persisted failing on „Maximum execution time exceeded.“ Based on your tips I changed simply `localhost:3000` to `127.0.0.1:3000` in the address bar and problem solved. Endless loading was limited to Chrome only, by the way, even with all extensions turned off. – Kout Oct 25 '16 at 08:29
  • Freaking important for everyone on macOS –  Feb 26 '18 at 17:04
  • This is madness, same here, I changed from .local to .dev and it works perfect, I am on a Mac – George Jul 25 '18 at 08:35
  • 5
    Note that .dev in Chrome nowadays forces a redirect to https, which I don't want locally. Forces me to use .test now. – kapoko Sep 04 '18 at 14:15
  • See the solution below. It's basically special lookups on that domain which require the extra hosts entry to pre-resolve. ::1 – Dtipson Apr 23 '20 at 14:17
41

What you experience is most likely the result of Bonjour IPv6 lookups being issued for DNS lookups on .local domains. These IPv6 lookups create a timeout delay until the original IPv4 DNS lookup is issued.

The solution of @RicoLeuthold works, because .dev domains do not trigger Bonjour lookups on macOS. But it can be terrible to change all your vHosts if you already have many of them running on .local domains with projects configured to use these .local domains too.

ALTERNATIVE SOLUTION

An alternative is to add an additional IPv6 localhost entry in your hosts file (on Linux: /etc/hosts, on macOS usually: /private/etc/hosts) for each IPv4 .local entry.

Change this hosts content...

127.0.0.1   phpmyadmin.local
127.0.0.1   project1.local
127.0.0.1   project2.local

...to that hosts content...

::1 phpmyadmin.local
127.0.0.1   phpmyadmin.local
::1 project1.local
127.0.0.1   project1.local
::1 project2.local
127.0.0.1   project2.local

  
TIP: USE A REGEXP EDITOR

If you are using an editor like Atom or Sublime Text capable of regexp search/replace, here is a pattern to update your hosts file:

Search:
(127.0.0.1)(.*)$
Replace:
::1$2\n$1$2

This pattern will also add IPv6 entries to the general IPv4 localhost entry at the top of the hosts file. After doing the search/replace you should check the top of your file for a duplicate entry of...

::1  localhost

... and remove one of the duplicates.

Jpsy
  • 20,077
  • 7
  • 118
  • 115
  • 8
    Oh wow! This just blew my mind. It's SOOO much faster now! I was wondering why when I came home to work it was slower than the network at my work. You just saved me! Thanks! – Aaron Olin Nov 23 '17 at 15:51
  • 7
    Boom. That's a hell of a tip. – rob_was_taken Jul 04 '18 at 14:36
  • 4
    @Jpsy Thank you so much - I was seeing delays of up to 20s on every refresh, no it's almost instant! This is going to be a great time-saver for me :-) THIS should be the accepted answer! – simonl Apr 12 '19 at 11:25
  • 2
    Blazing fast. Works like a charm when using BrowserSync + HTTPS. – Jimmy Adaro Jun 07 '19 at 20:57
  • 2
    Thank you so much for the explanation! It is good to know why something is taking so long. While accepted answer may have solved it, you have demystified it for us. I've learnt a valuable lesson about possible causes of slowness w.r.t. web/dev servers! – SidOfc Dec 06 '19 at 14:38
0

In my case I was using windows. After analyzing network tab on firebug I noticed few images were missing. As soon as I fixed images it worked fast!

Maximus
  • 2,906
  • 4
  • 35
  • 55
0

I have tried something else and did worked for me very well.

I have disabled IPv6 on my mac with the following command:

networksetup -setv6off Wi-Fi

You can switch it back on like this:

networksetup -setv6automatic Wi-Fi

I did not wanted to switch to .dev because all my sites are set up more like this:

Live site: https://www.myawesomesite.com
Local site: https://dev.myawesomesite.com