I have the following code that I run on each HTTP request:
ScriptEngine jsEngine = ScriptEngineManager.new().getEngineByName("nashorn");
jsEngine.eval("some script");
jsEngine.invokeMethod(jsEngine.eval("foo"), "bar");
It works, but it's extremely inefficient as my unchanging JavaScript is evaluated every time. What's the proper way to re-use the evaluated JavaScript?