code: def make_refresh_script(path, x_rebuild_time):
      """
      Create a snippet of javascript to inject into static pages.
  
      The snippet should reach back to our http server and long-poll for updates.
      """
      x = str(x_rebuild_time).encode("utf8")
      return (
          b'''
          <script>
              start_check = function() {
                  let xhr = new XMLHttpRequest();
                  xhr.open("POST", "/");
                  xhr.setRequestHeader("X-rebuild-time", "'''
          + x
          + b'''");
                  xhr.setRequestHeader("X-rebuild-path", "'''
          + path.encode("utf8")
          + b"""");
                  xhr.send();
                  xhr.onload = function() {
                      // alert(`Loaded: ${xhr.status} ${xhr.response}`);
                      if (xhr.response === "new") {
                          window.location.reload(false);
                      } else {
                          start_check();
                      }
                  };
                  xhr.onerror = function() {
                      // server is dead, refresh page to make that obvious.
                      window.location.reload(false);
                  }
              }
              start_check()
          </script>
          """
      )
  
imports: import http.server
  import os
  import subprocess
  import sys
  import threading
  import time
  import watchdog
  import watchdog.events
  import watchdog.observers
label_desc: Use image node_id 1 for calling a global function with example usage: make_refresh_script(path, x_rebuild_time) and returns: unknown