Skip to content

Instantly share code, notes, and snippets.

View acortelyou's full-sized avatar

Alex Cortelyou acortelyou

View GitHub Profile
@acortelyou
acortelyou / live-refresh.js
Created November 6, 2019 18:24
Reload a page when modified on the server
var origModified = "";
var check = function(){
var xhr = new XMLHttpRequest();
xhr.open("HEAD", window.location.href, true);
xhr.onreadystatechange = function() {
if (this.readyState != 2) return;
var lastModified = xhr.getResponseHeader("Last-Modified");
if (!origModified) origModified = lastModified;
else if (origModified != lastModified) location.reload(true);
};