[GIS] How to speed up OpenLayers with WFS in IE

openlayers-2wfs

I'm using Openlayers, Geoserver and noticed that IE is very very slow to display WFS layers. I haven't so many WFS features, about 300. Google base layer appears after 1 sec. but my two WFS layers need each from 10 to 20 seconds to display. With Chrome, it requires only 2 seconds.

I tried to disable style rules, events, no change. It's really a client issue, my cpu goes up to 50% for iexplore during features loading. I tried with IE8 and 9, with two differents pc, same results.

It seems that I'm not the only one. I can keep using Chrome but would be interested to share ideas

Olivier

Best Answer

We are using OpenLayers 2.13.1 with the Dutch PDOK map implementation and were experiencing severe performance problems with WFS sources. I found a simple way to speed IE up by about a factor 2. It is still slow, but at least there is a significant improvement. Also it seems to use less CPU than before.

When profiling, I noticed that the most time is spent in the XMLHttpRequest.responseText property. Looking at the OpenLayers code, I saw that a version of https://code.google.com/p/xmlhttprequest/ is used. That class was intended to emulate XMLHttpRequest for Internet Explorer versions lacking a built-in XMLHttpRequest object. However, this should not be required in IE9 and newer, and Open Layers 2.x does not work properly in older IE versions. IE < 9 has become very uncommon anyway, even for the most convervative of our customers.

To make a long story short, here is how to speed up Open Layers 2 in IE:

  • Start with OpenLayers.debug.js (unminified code)
  • Look for the XMLHttpRequest.js code block
  • Replace the browser sniffing code at the start of the class by:

    var bGecko = !!window.controllers, bIE = false, bIE7 = false;

  • Look for occurences of the text "ActiveXObject". Ensurte that all code depending on this is not executed. E.g.,

    if (false /* window.ActiveXObject */) {

  • Finally, a fix is needed for a namespace problem in IE. Look for this function inside OpenLayers.Format.XML:

    write: function (node) {

  • Add this code just before the closing bracket of the function:

    if ("ActiveXObject" in window) // If IE is detected

    data = data.replace(new RegExp('xmlns:NS\d+="" NS\d+:', 'g'), '');

  • After testing the fix, re-minify the code for release, e.g., by using Microsoft's Ajax minifier.

The replace statement was always needed to get WFS to work in IE11 and Edge. After disabling the XMLHttpRequest emulation, the same applies to older IE versions as well.

[edit]In addition to the above, we should fully avoid accessing request.responseText in IE. With the built-in XMLHttpRequst object, responseXML should always be available and valid. In my test, the original code spent about 8000 ms in responseText and 600 ms in responseXML. Actually, we do not need responseText at all in WFS.

Additional changes:

  • In function fGetDocument(oRequest) remove all code related to sResponse, leave only oDocument
  • In function fSynchronizeValues(oRequest) set oRequest.responseText = '';
  • Replace var response = arcxml.parseResponse(request.responseText); by var response = arcxml.parseResponse(request);

With these changes, no more time is spent in responseText, while the time spent in responseXML does not increase. I have also tested WMS and WMTS layers, they still work as before. I've repeated all tests in firefox and chrome, dit not find side effects.

[/edit]

Hope this helps,

Berend

Related Question