demandio / ember-prerender

Make your Ember.js web apps crawlable by rendering static HTML on the server.
MIT License
140 stars 13 forks source link

Reading html from phantom (not from index.html by FS) #10

Closed shumkov closed 10 years ago

shumkov commented 10 years ago

Now prerender has bad restriction - it must be placed on a same server with a JS project. Why we can't get html from baseURL?

Stanback commented 10 years ago

I'll revisit this - the reason I'm reading index.html from the FS is so that I can manipulate the HTML before sending it to Phantom or JSDOM. I have a plugin hook called beforeInit, which gets used by the removeScriptTags.js plugin to remove Google Analytics and custom fonts.

Stanback commented 10 years ago

I've merged in pull request #11 for dealing with this issue.

I'm now using the 'request' library to fetch the index.html page from baseUrl + applicationPage and then I feed the HTML into Phantom or JSDOM. This allows us to preserve the plugin logic for pre-processing of the HTML, such as removing Google Analytics code, etc.

In the future, I may try experimenting with telling Phantom and JSDOM to fetch index.html directly - I can use onResourceRequested to have Phantom skip certain hosts/files, and JSDOM has something similar called SkipExternalResources.

Let me know if you have any issues and I'll re-open.

shumkov commented 10 years ago

Thanks