if ("WebSocket" in window) {
  (function () {
    var protocol = window.location.protocol === "http:" ? "ws://" : "wss://";

    var address =
      protocol + window.location.host + window.location.pathname + "/ws";

    var socket = new WebSocket(address);

    socket.onmessage = function (msg) {
      if (msg.data == "reload") window.location.reload();
    };
  })();
} else {
  console.error(
    "Upgrade your browser. This Browser does NOT supported WebSocket, and cannot do live reloading."
  );
}
