Last active
September 27, 2016 11:49
-
-
Save branneman/37865bcfc5d102c2be6c to your computer and use it in GitHub Desktop.
Conditioner.js bootstrap with JavaScript Mustard Cut & Polyfill loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
... | |
<script> | |
(function(d){ | |
if (!('querySelector' in d && 'addEventListener' in window)) return; | |
d.documentElement.className += ' has-js'; | |
d.addEventListener('DOMContentLoaded', function() { | |
var s = d.createElement('script'); | |
s.setAttribute('src', '/static/js/vendor/requirejs/require.js'); | |
s.setAttribute('data-main', '/static/js/main'); | |
d.body.appendChild(s); | |
}); | |
}(document)); | |
</script> | |
</head> | |
<body> | |
... | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
require.config({ | |
map: { | |
'*': { | |
classList: 'polyfills/classList', | |
conditioner: 'vendor/conditionerjs/conditioner' | |
} | |
} | |
}); | |
var polyfills = []; | |
if (!('classList' in document.documentElement)) { | |
polyfills.push('classList'); | |
} | |
// ... more feature detections ... | |
require(['conditioner'].concat(polyfills), function(conditioner) { | |
conditioner.init(); | |
}); | |
}()); |
Haha, brilliant! :-) Excellent plan to leave minifying to the pros ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Manual minification, I love it. We can do even better:
Also, would it be possible to shorten both the
setAttribute
calls? I knows.src =
will work, but will this work for the data attribute as well?Or we could go crazy and save more bytes:
On second thought, let's stop here ;) We should leave minification to a minifier.
Anyway, I've updated the gist with the sane changes.