Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 1 KB

README.md

File metadata and controls

45 lines (34 loc) · 1 KB

vim command + JS snippet for crapshoot livereload

screen recording

" use in vim
:autocmd BufWritePost * execute "!echo `date` > %.update"
<!-- add in webpage -->
<script src="https://www.alexstachowiak.com/livereload.js"></script>

The Algorithm

  1. Serve files using python -m SimpleHTTPServer 8869

  2. Update a file, "$file.update", on save

:autocmd BufWritePost * execute "!echo `date` > %.update"
  1. Reload webpage when change is detected
/* Also at: https://www.alexstachowiak.com/livereload.js */
<script>
  let current = null;
  setInterval(() => {
    fetch(window.location.href + '.update')
      .then(r => r.text())
      .then(content => {
        if (current == null)
          current = content;
        else if (current != content)
          window.location.href = window.location.href;
    })
  }, 1000);
</script>

Works for index.html, etc., but the save command will need to be updated if the file and URL don't share a name.