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

Web worker support? #168

Open
simonmysun opened this issue Nov 28, 2016 · 5 comments
Open

Web worker support? #168

simonmysun opened this issue Nov 28, 2016 · 5 comments

Comments

@simonmysun
Copy link

It seems taking very long time rendering large document especially those including MathJax rendered formulas. Since loading an image is asynchronously done by browser, this library seems to be the only thing stucking the browser. I've read the code and havn't found any part producing the data URL which need document object. I think it would be nice to support doing this inside a web worker.

P.S. I really love this project. If I were able to improve it I would really like to pull request. Thank you for providing it.

@simonmysun
Copy link
Author

Actually I mean that the library should work in worker when it only receive HTML and produce Data URL. Or parsing HTML can be done with silently copying the element.

@cburgmer
Copy link
Owner

Hey, there actually is quite a bit of code that needs to have access to the document or window object:

  1. calculating the required canvas size (https://github.com/cburgmer/rasterizeHTML.js/blob/master/src/browser.js#L175),
  2. parsing HTML (https://github.com/cburgmer/rasterizeHTML.js/blob/master/src/browser.js#L241),
  3. executing JavaScript that's included in a document (https://github.com/cburgmer/rasterizeHTML.js/blob/master/src/browser.js#L30),

only to name a few.

In fact web workers only have very limited access judging by https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Functions_and_classes_available_to_workers.

The only way that I currently see for moving towards web workers is to

  1. be limited to a subset of features that this library currently exposes, and
  2. replacing some of the dependencies on the browser with pure NodeJS libraries (like parsing HTML).

But then this already sounds like a bit of a rewrite/separate direction.

I haven't looked into this into more detail though, and I'm happy to be proven wrong. Might be worth giving it a try if you want :)

@cburgmer
Copy link
Owner

@chuyik If you need full server side rendering, PhantomJS, SlimerJS or headless Chrome might be an option.

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

No branches or pull requests

3 participants
@cburgmer @simonmysun and others