toolness / p5.js-widget

A reusable widget for embedding editable p5 sketches in web pages.
https://toolness.github.io/p5.js-widget/
GNU Lesser General Public License v2.1
162 stars 44 forks source link

Lazily load dependencies for running sketches #20

Open toolness opened 8 years ago

toolness commented 8 years ago

Right now we sort of do this because the main widget doesn't actually contain p5--rather, the preview frame directly loads it over CDN, and the preview frame isn't created until the sketch starts playing.

However, we also mangle the code via esprima in the widget prior to running it, and that's a fairly big dependency. Possibilities:

  1. Use Webpack code splitting to lazily load esprima and other such dependencies in the widget.
  2. Build a separate Webpack bundle for the preview frame (done in #21), and move the code-mangling logic into the preview frame.

Another non-mutually-exclusive option is to switch to a different AST parser, such as acorn (not sure how its size compares to esprima, though).