HtmlUnit slower than GUI browser?

Why is HtmlUnit so much slower than GUI browsers? For example, HtmlUnit loads this page http://oltexpress.airkiosk.com/cgi-bin/airkiosk/I7/181002i?O2=2 in 14 seconds (when CSS support is disabled), while FF does it in 5 seconds ( after clearing the cache, with CSS support). I know that modern browsers do not so restrict the work with bad JS code, while there is HtmlUnit, but still the time difference is unbearable here.

Any ideas how to speed up your work with HtmlUnit? Has anyone played with the HtmlUnit cache?

+5
source share
3 answers

To answer the question of why it is slow:

This is because HTMLUnit has a lot of things against it:

  • , , FireFox.
  • XML, HTML (), , HTML XML.
  • JavaScript , , Java.
  • , @Arya, , javascript , .

, :

, ( ):

  • JavaScript
  • CSS
  • .

ActiveX . , , , , .

WebClient browser;
browser.setWebConnection(new WebConnectionWrapper(browser) {
    @Override
    public WebResponse getResponse(final WebRequest request) throws IOException {
        if (/* Perform a test here */) {
            return super.getResponse(request); // Pass the responsibility up.
        } else {
            /* Give the program a response, but leave it empty. */
            return new StringWebResponse("", request.getUrl());
        }
    }
});

, :

  • HTMLUnit , , , .
  • HTMLUnit
+5

, HTMLUnit, , . , . JS css IMO

+1

WebClient . WebClient , .

To avoid this, you can reuse the WebClient object in multiple sessions or even maintain a pool of WebClient objects. Also see if you can save the Cache object . You can clear the WebClient cookie before returning it to the pool.

As @Lee points out, WebConnectionWrapper gives you the ability to intercept. I use it to avoid forwarding, disable JS execution for selected resources, or return data if I do not need this resource.

0
source

All Articles