0

We run our application on partners websites using widgets under async iframes.

One of our servers is unreachable from some networks, and some users are claiming about continuous "Loading from our.domain.com ...", causing direct interference on user experience.

It is possible to abort resource loading when network error occurs?

Our environment cannot depends of any external lib (like jquery, zepto, ...). Our code is written in raw javascript.

We tried to remove javascript element after some timeout, like described on some resources here on SO, but no one works.

Here, is one snippet of testing code. This removes <script> element after 1s if it is not ready.

setTimeout(
    function(){
        //Check if it is ready using a control var
        if (! contextControl.isReady){
            // Not Ready
            var trgt = document.getElementById("element-id");
            //force element drop
            trgt.parentNode.removeChild(trgt);
        }
    }, 1000
);

It removes javascript element effectively, but doesn't abort resource loading.

There is some effective way to abort this resource loading?

Andre Pastore
  • 2,841
  • 4
  • 33
  • 44

1 Answers1

0

I would try to use asynchronous loading with error handling:

$.getScript( "ajax/test.js" )
  .done(function( script, textStatus ) {
    console.log( textStatus );
  })
  .fail(function( jqxhr, settings, exception ) {
    $( "div.log" ).text( "Triggered ajaxError handler." );
});

http://api.jquery.com/jQuery.getScript/

Pierre
  • 558
  • 1
  • 7
  • 36
  • I forget to advise. We do not use jquery on clients websites. We removed this dependency. – Andre Pastore Jul 23 '14 at 15:05
  • you can create your own function, check http://stackoverflow.com/questions/7718935/load-scripts-asynchronously – Pierre Jul 23 '14 at 15:22
  • The function to inject script is working correctly. We have an issue on abort script loading after some network problem. It is similar to .fail() call you wrote above. But, what we need is something like a timeout control and interruption of browser script loading. – Andre Pastore Jul 23 '14 at 16:43