Test Pages within 5 seconds loading pattern

Asked

Viewed 38 times

0

I will select some sites by hand, to catalog and make available later and I have in mind to prioritize users that uses mini-modem USB 2G/3G on Personal Computer (PC), in which the connection is somewhat limited.

For this I need to know the type of Website that they will have better visualization and usability, whether or not is instânanea presentation of the contents of these pages.

We will use a text field where will be inserted a URL of any Web, and the button to which will direct the opening of this within a iframe.

The logic

Imagine for example that, inside the page where you will check if it is equal to or greater than 5 seconds the time onload. If it is longer than 5 seconds, then discontinue loading the URL and issue a alert(); of the kind "Huuumm! This page escapes our 2G standards (EDGE)"

But if the number of seconds is less then allow charging and finally emit 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 the charging time will be made one of the two actions within <iframe></iframe>

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

  • What code do you have so far?:

1 answer

1

I do not know if this is the right way to solve the problem, and if it is no longer worth your server to load a first page, do a timestamp before and after, and consider whether the user will be able to load or not; However, you can always check the Document of the X iframe 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 keep thinking that it will be more correct for the server to decide the load time, to save this value to be used in the future, and to tell the user whether or not to load a good load.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.