Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8431049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:45:08+00:00 2026-06-10T05:45:08+00:00

On a recent project I used Alexander Farkas’ HTML5 Shiv and I noticed that

  • 0

On a recent project I used Alexander Farkas’ HTML5 Shiv and I noticed that when minified the script was 2.274 KB. This seemed pretty large to me for a concept that John Resig demonstrated in essentially two lines (I realize that this is highly oversimplified, because John’s doesn’t include a check for support or all of the new HTML5 elements). I dug into the html5shiv source. It was 248 sloc, which seemed like a lot of unnecessary code for such a simple task. I achieved a much simpler shiv in only 14 lines:

(function(document) {
    var div      = document.createElement('div'),
        elements = 'article|aside|audio|canvas|details|figure|figcaption|footer|header|hgroup|nav|output|progress|section|summary|video'.split('|'),
        i        = 0,
        length   = elements.length;

    div.innerHTML = '<header></header>';

    if(div.childNodes.length != 1) {
        for(; i < length; i++) {
            document.createElement(elements[i]);
        }
    }
})(document);

Minified it’s only ~270 bytes (that’s an 88% savings from the size of the Farkas Shiv). When combined with appropriate CSS, it worked correctly in IE 6, 7, and 8.

article,aside,audio,canvas,figure,figcaption,footer,header,hgroup,nav,output,progress,section,video{display:block;}

It seems that the meat of the Farkas shiv does some magic with creating elements and checking for functions within a try/catch. Is this meat and filler necessary? Is my solution adequate enough or does the Farkas shiv account for something I haven’t considered?

EDIT

The script now creates it own style tag with the proper declarations (and still is only 21 lines!):

(function(document) {
    var div      = document.createElement('div'),
        elements = 'article,aside,audio,canvas,figure,figcaption,footer,header,hgroup,nav,output,progress,section,video',
        elementArr = elements.split(','),
        i        = 0,
        length   = elementArr.length,
        script, style;

    div.innerHTML = '<header></header>';

    if(div.childNodes.length != 1) {
        for(; i < length; i++) {
            document.createElement(elementArr[i]);
        }

        script = document.getElementsByTagName('script')[0];
        style = document.createElement('style');
        style.innerHTML = elements+'{display: none}';
        script.parentNode.insertBefore(style, script)
    }
})(document);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:45:10+00:00Added an answer on June 10, 2026 at 5:45 am

    The main difference between your code and html5_shiv is that your version only caters for IE’s lack of support for the HTML5 elements during the initial loading of the page.

    There are, in fact, significant further issues to be dealt with, which you will encounter if you use Javascript to modify the page content after loading.

    At one point, there was actually a secondary script called html5 inner shiv, which solved these problems. However, more recent versions of the main html_shiv script have incorporated these fixes as well, so the secondary script is no longer required. But it does mean that the main script is now a lot bigger.

    This accounts for the amount of code you’ve seen.

    If your HTML is going to be static, then the answer is no, you don’t need all that extra code; your version is fine. (or you could go to the html5_shiv Github page and download a previous release; the early versions looked a lot more like your code).

    But if you intend to write a site with any kind of dynamic content, then you would be well advised to use the full current version of html5_shiv. It fixes more than just the one issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a recent project I have nearly completed we used an architecture that as
In a recent VB.NET project I adopted the naming conventions I'm used to using
In a recent embedded project, we have used the following svn structure: project branches
Hey guys in my recent project i have used the valums file uploader for
A recent project called for importing data into an Oracle database. The program that
In a recent project I have found that they're using smarty and the client
I have a project that runs Python 2.7, PyGTK 2.24, and the most recent
I working on a project that used Azure Table Storage. The data is stored
I've used bigbluebutton in a recent project in order to build a web conferencing
In a recent project of mine, i've got up to a good stage where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.