Skip to content
This repository was archived by the owner on Oct 9, 2019. It is now read-only.

Support Proposes Best Practise for Indicating that Content of SPA is Ready #4

Closed
vanthome opened this issue Apr 10, 2014 · 9 comments
Closed

Comments

@vanthome
Copy link

The XContentReady Event might be worth to support. What do you think?

@Stanback
Copy link
Member

Sounds like a good initiative. I've renamed the event I'm using from PrerenderReady to XContentReady in commit ce28922

@vanthome
Copy link
Author

Great, thanks. I've advertised a bit at other projects like this one [1 - 2], let's see if we get some momentum.

[1] prerender/prerender#84
[2] herval/render_static#1

@Stanback
Copy link
Member

Cool. I saw the comment from Todd about prerender and the issue with combining request counting with event listening. Perhaps he can add a configuration option that specifies whether to rely on events or request counting.

I noticed that PhantomJS doesn't support CustomEvent so I'm using the old document.createEvent method instead.

@vanthome
Copy link
Author

I've commented on it and proposed a solution.

Interesting catch regarding Phantom as I'm just trying to get a PoC working. Where did you learn about the fact that Phantom does not support it?

@Stanback
Copy link
Member

When I tried instantiating CustomEvent, Phantom complained about it not existing. It worked in my browser but it seems strange that Phantom wouldn't support it. I'll try to investigate further over the weekend.

@vanthome
Copy link
Author

So far in my experiments, I'm not able to catch the event at all. I tried these both variants to throw it:

var e = new CustomEvent('XContentReady', { bubbles: true, cancelable: false });
document.dispatchEvent(e);

var prerenderEvent = document.createEvent('Event');
prerenderEvent.initEvent('XContentReady', true, false);
document.dispatchEvent(prerenderEvent);

And I can catch non-custom DOM events.
I'm using phantom JS 1.9.7.

@Stanback Stanback reopened this Apr 18, 2014
@Stanback
Copy link
Member

@vanthome I've created an example at https://gist.github.com/Stanback/11068255 (it works for me using PhantomJS 1.9.7). I'm attaching an event listener to the active page, which notifies Phantom via window.callPhantom().

If I use CustomEvent, Phantom returns the following error:

ReferenceError: Can't find variable: CustomEvent

@vanthome
Copy link
Author

Thx! I came up with more or less the same solution using window.callPhantom() but I think I had some issue so that the event was not fired -- working now. I have updated the spec with a hint that the custom event cannot be used as of Phantom 1.9.7.

@Stanback
Copy link
Member

Cool - the hint looks good.

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

No branches or pull requests

2 participants