title: I want to speed up the eval of Nashorn
body: <p>I was allowed to run the <a href="https://github.com/dropbox/zxcvbn" rel="nofollow">zxcvbn.js (Javascript library)</a> to Nashorn.
  But there is one problem.</p>
  
  <p>eval (pre-compile) is very slow. It takes about 3 minutes.
  I want to move more quickly.</p>
  
  <pre><code>public class StrengthChecker {
  
    private static final String ZXCVBN_PATH = "/META-INF/resources/webjars/zxcvbn/1.0/zxcvbn.js";
  
    private final ScriptEngine engine;
  
    public StrengthChecker() {
      ScriptEngineManager manager = new ScriptEngineManager();
      engine = manager.getEngineByName("nashorn");
  
      Bindings engineScope = engine.getBindings(ScriptContext.ENGINE_SCOPE);
      engineScope.put("window", engineScope);
  
      try {
  
        // -------------------------------------------
        // Here is very slow definition of zxcvbn.js.
        // -------------------------------------------
        engine.eval(getResourceContents(ZXCVBN_PATH));
  
      } catch (ScriptException e) {
        throw new RuntimeException(e);
      }
    }
  
    public Strength check(String pw) {
      try {
        Map&lt;String, Object&gt; result;
        result = (Map&lt;String, Object&gt;) engine.eval("zxcvbn('" + pw + "');");
  
        return new Strength(
          ((Double) result.get("entropy")).intValue(),
          (int) result.get("score"),
          ((Double) result.get("crack_time")).intValue()
        );
      } catch (ScriptException e) {
        throw new RuntimeException(e);
      }
    }
  
  }
  </code></pre>
  
  <p>Please tell us something solution.</p>