Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11528 - IE <= 8 can't serialize html5 elements sometimes #718

Closed
wants to merge 3 commits into from
Closed

Fixes #11528 - IE <= 8 can't serialize html5 elements sometimes #718

wants to merge 3 commits into from

Conversation

cmcnulty
Copy link
Contributor

Basically this patch just excludes innerHTML from being used in the .html() function if an html5 tag is being inserted and the ie serialization bug is present. This forces it to use the append method, which should properly apply the html5shiv code.

if ( !jQuery.support.htmlSerialize ) {
wrapMap._default = [ 1, "div<div>", "</div>" ];
wrapMap._default = [ 1, "X<div>", "</div>" ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the "div" text is just a shim, it can be anything. I use "X" to shave off the two characters. It would ideally be something like "shim" if every byte of jquery didn't translate into petabytes of internet traffic. Personally I found it more confusing as "div" than as "X".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could try changing X to c to check if the GZIP algo will better optimize the c<d part of the string - which is used several times throughout the minified jQuery 1.7.2 source.

</bikeshed>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My tests show that switching it from "div" to "X." shaves off one gzipped byte. I tried "c" and even ">" and got the same number of bytes as "X".

And actually I appreciate the reminder to think about gzip results. Byte count, compressed or uncompressed, isn't much of a priority in my day job, so I often overlook it. The real reason I wanted to replace "div" is that it makes it look somehow magical, like it needs to be that particular text, when in fact it can be any character at all.

(edit - trying to make it so that the divs don't gobble up the text)

@rwaldron
Copy link
Member

Looks good in the IEs (6,7,8)

@jdalton
Copy link
Member

jdalton commented Mar 29, 2012

+1, I use x for my stuff too.
Big props for jQuery anyway on using this technique, though it existed before jQuery's use, I first saw it in jQuery while researching the problem for Prototype in '08.
(5 years after jQuery picked it up and other libs still haven't caught on)

@dmethvin
Copy link
Member

dmethvin commented Apr 2, 2012

+1 on the use of something other than div there, should have changed it long ago. We'll land this for 1.8.

@dmethvin
Copy link
Member

dmethvin commented Apr 5, 2012

Landed in 1.8pre, 4cd57d7. Thanks!

@dmethvin dmethvin closed this Apr 5, 2012
@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants