estrattonbailey / operator

1.8kb drop-in "PJAX" solution for fluid, smooth transitions between pages.
90 stars 11 forks source link

Further improve script eval #5

Closed estrattonbailey closed 7 years ago

estrattonbailey commented 7 years ago

From MDN:

What if your code is in a JS string? Instead of using eval or innerHTML, both of which trigger synchronous compilation, you should use a Blob with an object URL:

var blob = new Blob([codeString]);
var script = document.createElement('script');
var url = URL.createObjectURL(blob);
script.onload = script.onerror = function() { URL.revokeObjectURL(url); };
script.src = url;
document.body.appendChild(script);