5

I have an HTML like this:

<!-- simulate a slow-loading request -->
<script src="http://example.com:81/non-existent-script.js"></script>

<script>
    $(document).ready(function() { alert("ready"); })
</script>

(see http://jsfiddle.net/mK63F/)

When I open the page in Chrome, the example.com request should hang - but then, when I hit F5, the "ready" alert appears, before the page refreshes. Why does that happen? And how to distinguish that situation (i.e. refresh during page load) from "normal" page ready?

ivan_pozdeev
  • 28,628
  • 13
  • 85
  • 130
hmp
  • 921
  • 3
  • 10
  • 27

2 Answers2

2

When you click f5 browser stops all active requests and ready function is ruining Because everything is loaded ...

alternative is

$( window ).load(function() {
  alert("loaded");
});

http://jsfiddle.net/26x2K/4/


LINK HERE

.load not running if all request dont get the success responce

Also Read - jquery what are differences between document ready and window load

Community
  • 1
  • 1
Anri
  • 1,607
  • 2
  • 15
  • 34
1

When you hit F5 for reload the request gets canceld. You can see this in devtools with status canceld:

enter image description here

Therefore the document is ready because no requests are loading anymore.

Community
  • 1
  • 1
jhinzmann
  • 918
  • 6
  • 15