rails/turbolinks — pull request #425 by tomafro (2014-11-03 14:03:07+00:00)
Title: Use document.documentElement.cloneNode() when parsing to fix resolution independence

This follows on from issue https://github.com/rails/turbolinks/issues/413 (which has a fair bit more background info).

In order to fix the resolution independence issues we've been seeing (where the @1x image is always chosen
even when higher resolutions would be appropriate) we've been using the `createDocument` function in this
pull request, using document.documentElement.cloneNode() in place of the other document creation techniques. We've been using this on a staging environment and so far have seen no issues.

For this initial pull request I've ripped out all of the other document creation functions as it seems cleaner to
me to use a single function across all browsers with a fallback only where necessary. Unfortunately I'm not really clear how to check where a fallback would be necessary. I've done sanity checks on Chrome, Safari, Opera, IE10, iOS Safari, Android Chrome, and Firefox and it all looks good, but what else should I look at to add confidence?

I have written a performance check and it seems that using `cloneNode()` is generally faster (though performance is so high already there's no appreciable benefit): http://jsperf.com/compare-turbolinks-document-creation

Any comments, questions, and help getting this pull request either improved or rejected will be gratefully received.