Skip to content
Advertisement

Details about window.stop()

I just came across the window.stop()

The stop() method is exactly equivalent to clicking the stop button in the browser. Because of the order in which scripts are loaded, the stop() method cannot stop the document in which it is contained from loading, but it will stop the loading of large images, new windows, and other objects whose loading is deferred. https://developer.mozilla.org/en-US/docs/Web/API/Window.stop

I am wondering:

  1. What do ‘windows’ and ‘other objects whose loading is deffered’ refer to? Can somebody give me a practical example?
  2. If I append an image to the body and call window.stop() when 30% has been loaded, and then append the same image at a later time; will the latter image only have 70% left load?

Advertisement

Answer

What do ‘windows’ and ‘other objects whose loading is deffered’ refer to? Can somebody give me a practical example?

new windows could be iframes or regular frames. Scripts themselves can be marked as defer which loads them after the document and after other inline scripts so these could also be stopped with window.stop(). So practical examples of objects that might have their loading stopped are: iframes, embedded objects (like Adobe Flash), scripts marked defer and images. The idea here is that if you’re going to call window.stop() from a script in the page, it can only apply to resources that have not yet completed loading. By definition, at least part of the document and your script have already completed loading or the script wouldn’t be running so you could call window.stop() so it is primarily going to apply to resources that are loaded later in the load process such as the ones above.

If I append an image to the body and call window.stop() when 30% has been loaded, and then append the same image at a later time; will the latter image only have 70% left load?

The browser cache is very unlikely to cache 30% of an image and then resume loading only the remaining 70% the next time you ask for that resource. Most caches just refuse to cache an object if it is not completely loaded. In any case, this would be entirely browser dependent as this type of behavior of the cache is outside of the standards.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement