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

Make InstantClick work on more sites without configuration #94

Closed
wants to merge 18 commits into from

Conversation

zackbloom
Copy link

The goal of these changes is to make IC work on more sites without requiring the addition of data- attribute configuration. Before these changes, it was common for sites which had changes in their head to break after IC navigation. I tried to make the commit messages descriptive, so please consult them for a specific list of the changes required.

Here's a few examples of sites broken w/ master which now work:

  • dropbox.com – Click “Mobile” in the footer
  • mit.edu – Click “About” or “Visiting"
  • twitter.com/privacy – Click “About Us” in the footer
  • nytimes.com – Click “Opinion” in the top nav, or worse, click an article title
  • apple.com – Click “iPhone"
  • github.hubspot.com/offline/docs/welcome – Click “Documentation”

The one note about these changes is they don't target Firefox before version 13. This amounts to about 0.2% of the web browser market. If this is an issue, let me know and I will tweak the solutions to work on those older browsers as well.

Some sites such as Dropbox.com use attributes on script nodes to
define how they should be ran (or include non-js script nodes).

Previously, only the innerHTML and src attributes would be preserved,
often triggering errors or broken functionality.  This change
uses the cloneNode function to copy the node while preserving
all attributes.

cloneNode is not supported by FF before 13, so if legacy support is
desired an alternate solution will have to be found.
Previously assets in the head of the preloaded page wouldn't
be loaded, as only the body was copied.  After this change,
any tag in the head of the previous page, not in this page,
is added to the head after the switch.
function changePage(doc, newUrl, scrollY) {
updateHeadResources(doc.head)
updateAttributes(doc.head, document.head)
updateAttributes(doc.documentElement, document.documentElement)
Copy link
Author

Choose a reason for hiding this comment

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

updateAttributes allows us to propagate changes to the html or head elements attributes (i.e. classes) to the new page.

If someone has called `e.preventDefault()`, or returned false from
an event handler in IE8, respect that cancellation.
@adamschwartz
Copy link

Wow, great changes!

… again. Don't remove attributes to not break Typekit and the like.
… again. Don't remove attributes to not break Typekit and the like.
@CoolOppo
Copy link

CoolOppo commented Oct 9, 2014

Nice work.

@dieulot
Copy link
Owner

dieulot commented Oct 13, 2014

I have a million other things to do so I haven’t reviewed that yet, but if it’s as worthwhile as it sounds it’s very much appreciated!

@dieulot
Copy link
Owner

dieulot commented Dec 4, 2014

Sorry for making you wait so long, that’s a pretty big list of changes to review (and I’ve haven’t reviewed them all).

Adding stylesheets in the <head> unfortunately doesn’t work well: the body’s content will display first with the old style (the page will look broken) and then the layout will adjust. It brings an unpleasant flash (unless I’ve missed something that prevents that).

A mechanism to prevent that would add a lot of complexity, in my experience once you fight the browser’s default behaviors with JavaScript you then need an enormous amount of code to make it work well, so I prefer to keep InstantClick’s battles against the browser’s behaviors to a minimum. So unfortunately, it looks like InstantClick won’t ever be “plug and play”.

Thanks for making your fork of InstantClick progress though. There’s certainly good stuff to pick in there. I’ll check other commits in this PR a little bit at a time in the future, if there are things that catch my attention I’ll let you know and we’ll see to incorporate them into InstantClick.

@dieulot dieulot closed this Dec 4, 2014
@CoolOppo
Copy link

CoolOppo commented Dec 4, 2014

Adding stylesheets in the unfortunately doesn't work well: the body’s content will display first with the old style (the page will look broken) and then the layout will adjust. It brings an unpleasant flash (unless I've missed something that prevents that).

The unpleasant flash is called a flash of unstyled content. I just wanted to say that in case anybody didn't know.

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

Successfully merging this pull request may close these issues.

None yet

4 participants