Test Pages within the loading pattern 5 seconds

0

I'm going to select a few sites to hand, to catalog and make available later and I have in mind to prioritize users using a 2G / 3G USB mini-modem on the Personal Computer (PC), in which the connection is somewhat limited.

For this I need to know the WebSite type that they will have better visualization and usability, whether or not it instananea presentation of the content of those pages.

Let's use a text field where any URL of the web will be inserted, and the button to which it will direct the opening of an inside iframe .

The logic

Imagine for example that within the page where you will check if it is equal to or greater than 5 seconds the onload time. If it is longer than 5 seconds, it discontinues URL loading and issues a alert(); of type "Huuumm! This page runs away from our 2G (EDGE) standards"

But if the number of seconds is smaller then allow the upload and at the end issue another type of alert(); something like "Ok! This page is valid for 2G (EDGE) connections"

Reminder

  

The page that checks contains the scripts and a <iframe></iframe> , when compared to the loading time, one of the two actions will be done inside <iframe></iframe>

The part that is obscure for me is, how to stop loading a url into an iframe.

    
asked by anonymous 05.06.2016 / 17:47

1 answer

1

I do not know if this is the correct way to solve the problem, and if it is not worth your server to do a first load of the page, do a timestamp before and after, and consider if the user will be able to load or not; However, you can always check the X iframe document in X time;

function frameHasDocument(frameID) {
  return document.frames[frameID] && document.frames[frameID].document !== nulll;
  // se o frame.document é nulo, a pagina ainda nao fez loaded
}
var maxIterations = 10; // 10 iteraçoes a 1000ms cada = 10segundos
function takingTooLong() {
    if (maxIterations === 0 && !frameHasDocument('id-do-frame')) {
    document.frames['id-do-frame'].src = null;
    alert('demorou.');
  } else {
    console.log('passing..');
    setTimeout(takingTooLong,1000);
    maxIterations--;
  }
}

I still think that it will be more correct for the server to decide the load time, to record this value for future use, and to tell the user whether or not to do a good load.

    
06.06.2016 / 15:03