Skip to content

Instantly share code, notes, and snippets.

@peerreynders
Last active October 13, 2020 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peerreynders/57c52a13d1efa1311c6fc04b7603a23b to your computer and use it in GitHub Desktop.
Save peerreynders/57c52a13d1efa1311c6fc04b7603a23b to your computer and use it in GitHub Desktop.
Differential Serving
window._log('ECMAScript 2015 - with classes but no modules');
window._log('ECMAScript 2017 - classes and modules');
'use strict';
window._log('ECMAScript 5 - no classes, no modules');
<!doctype html>
<html lang="eng">
<!--
"A Universal Bundle Loader"
https://medium.com/@WebReflection/a-universal-bundle-loader-6d7f3e628f93
"Differential Serving"
https://css-tricks.com/differential-serving/
-->
<head>
<meta charset="utf-8"/>
<title>Differential Serving</title>
</head>
<body>
<p>JavaScript didn't execute</p>
<script>
(function() {
'use strict';
var element = document.querySelector('p');
element.textContent = '';
window._log = function (text) {
element.textContent += text;
};
}());
</script>
<script type="module">
window._ESM = !0;
import './es2017.js';
</script>
<script nomodule defer>
(function(g, d, es2015, es5) {
if(!g._ESM) {
var h = d.documentElement;
var s = d.createElement('script');
s.defer = !0;
s.type = 'text/javascript';
s.src = g.Reflect ? es2015 : es5;
h.insertBefore(s, h.lastChild);
}
}(window, document, './es2015.js', './es5.js'));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment