Skip to content

Instantly share code, notes, and snippets.

@aFarkas
Last active April 15, 2021 20:07
Show Gist options
  • Save aFarkas/11315175 to your computer and use it in GitHub Desktop.
Save aFarkas/11315175 to your computer and use it in GitHub Desktop.
minimal html5shiv
(function(createElement){
if(!('hidden' in createElement('a'))){
'abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video'.replace(/\w+/g, function(elem){
createElement(elem);
});
var p = createElement('p');
var parent = document.getElementsByTagName('head')[0] || document.documentElement;
p.innerHTML = 'x<style>' +
'article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block} ' +
'mark{background:#FF0;color:#000} template{display:none}' +
'</style>';
parent.insertBefore(p.lastChild, parent.firstChild);
}
})(document.createElement);
(function(createElement){
if(!('hidden' in createElement('a'))){
'abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video'.replace(/\w+/g, function(elem){
createElement(elem);
});
}
})(document.createElement);
@aFarkas
Copy link
Author

aFarkas commented Apr 26, 2014

Compared sizes between gist and normal html5shiv:

dist/html5shiv-minimal.min.js
Size: 585 bytes
Gzip Size: 386 bytes

dist/html5shiv-minimal2.min.js
Size: 277 bytes
Gzip Size: 212 bytes

dist/html5shiv-printshiv.min.js
Size: 4.03 Kb
Gzip Size: 1.91 Kb

dist/html5shiv.min.js
Size: 2.43 Kb
Gzip Size: 1.24 Kb

@jtwebb
Copy link

jtwebb commented Jun 25, 2015

@aFarkas Would this work just the same as the current html5shiv? I'd like to move modernizr to my footer, but need to include the shiv in the header. Is it safe (for IE8) to use this in place of the html5shiv?

And which would be better to use? minimal-1 or minimal-2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment