mrsum / webpack-svgstore-plugin

Simple svg-sprite creating with webpack
https://www.npmjs.com/package/webpack-svgstore-plugin
200 stars 92 forks source link

[IE9] XDomainRequest not fired onload #118

Closed DragorWW closed 7 years ago

DragorWW commented 7 years ago

in IE9 ./helpers/svgxhr.js XDomainRequest not run callback _ajax.onload;

if comment this code:

    // if (typeof XDomainRequest !== 'undefined') {
    //     _ajax = new XDomainRequest();
    // }

in ie9 start working loading sprite.

DragorWW commented 7 years ago

@mrsum what reason for close ?

mrsum commented 7 years ago

@DragorWW cause you can override svgxhr.js

DragorWW commented 7 years ago

@mrsum Yes, I did, but does not cancel bug. for other, my code witch path for ie9:

var svgXHR = function(options) {
    var url = false;
    var baseUrl = undefined;

    options && options.filename
        ? url = options.filename
        : null;

    if (!url) return false;
    var _ajax = new XMLHttpRequest();
    var _fullPath;

    if (typeof baseUrl === 'undefined') {
        if (typeof window.baseUrl !== 'undefined') {
            baseUrl = window.baseUrl;
        } else {
            baseUrl = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
        }
    }

    _fullPath = (baseUrl + '/' + url).replace(/([^:]\/)\/+/g, '$1');
    _ajax.open('GET', _fullPath, true);
    _ajax.onprogress = function() {};
    _ajax.onload = function() {
        if(!_ajax.responseText || _ajax.responseText.substr(0, 4) !== "<svg") {
            throw Error("Invalid SVG Response");
        }
        var div = document.createElement('div');
        div.innerHTML = _ajax.responseText;
        document.body.insertBefore(div, document.body.childNodes[0]);
    };
    _ajax.send();
};

module.exports = svgXHR;
ourfeel commented 7 years ago

The xdr.send() call is wrapped in a timeout to prevent an issue with the interface where some requests are lost if multiple XDomainRequests are being sent at the same time.