Skip to content

Instantly share code, notes, and snippets.

@asterick
Created May 1, 2014 00:21
Show Gist options
  • Save asterick/09762e6a321fa3c93c75 to your computer and use it in GitHub Desktop.
Save asterick/09762e6a321fa3c93c75 to your computer and use it in GitHub Desktop.
Replace all unrealized ESI's on a page (good for bookmarklets)
Array.prototype.forEach.call(document.getElementsByTagName("esi:include"),function(e){function r(e){n.after(e);console.log(t,"loaded");sessionStorage[t]=JSON.stringify({ts:+(new Date)+1e3*60*30,value:e})}var t=e.getAttribute("src"),n=$(e);if(sessionStorage[t]){var i=JSON.parse(sessionStorage[t]);if(i.ts>+(new Date)){r(i.value);return}}if(e.getAttribute("processed")){return}e.setAttribute("processed",true);var s=new XMLHttpRequest;s.open("GET",t,true);s.send();console.log("Loading",t);s.onreadystatechange=function(){if(s.readyState!==4){return}r(s.responseText)}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment