Code generation from strings disallowed for this context

Most js templating libraries rely on simple string2code evaluating to work. Is there any way to enable “unsafe-eval” for a specific worker?

Unfortunately, there is not. For security and future-proofing we don’t allow eval-ing of code in Workers. You can however use templating engines which allow you to compile your template to Javascript ahead of time, and then include that Javascript in your Worker.

@zack How do I include a JavaScript file that is not precompiled within the worker? Eg. when I load it from Amazon S3.

As far as I know, there’s no way to do that at this time, because that’s the same as eval.

1 Like