1

A slightly unusual problem. I need to limit the speed that an html page downloads at, and I need the code that achieves this to fit within the < head > section. Is this possible?

Tried PHP's sleep function but it seems to have no effect.

JasBot1983
  • 13
  • 2
  • Did you tried with ```lazy-load```? – marcdecline Oct 01 '19 at 22:33
  • 3
    please explain in greater detail what you are trying to achieve. For example, you can hide page with javascript for required time. Provide more details. – Noob Oct 01 '19 at 22:34
  • Do you mean from initial request from the browser or from first byte received from the response? There is a difference. – Jon P Oct 01 '19 at 22:34
  • I'm not sure. The end result I'd like is that the page loads slowly for the user, as if their connection speed is poor. – JasBot1983 Oct 01 '19 at 22:39
  • There are some good answers here: https://stackoverflow.com/questions/3536249/simulating-slow-internet-connection – Papa Oct 01 '19 at 23:02
  • 1
    Please tell us why you would like to achieve that. If it is to simulate slow network it is not possible (without extensions), but other reasons might be doable. – Akxe Oct 01 '19 at 23:15

1 Answers1

0

You could use setTimeout() as described on W3Schools.

First, you would change the display property of the body to none.

<body style="display:none">

Then you would create a function that gets the body element and changes the display property to block.

function myFunction() {
var body = document.getElementsByTagName("body")[0];
body.style.display = "block";
}

Followed by the use of setTimeout(). In the example below, I have set the timeout to 3 seconds. The function will execute after 3 seconds.

setTimeout(myFunction, 3000);

function myFunction() {
var body = document.getElementsByTagName("body")[0];
body.style.display = "block";
}
setTimeout(myFunction, 3000);
<html>
<head>
</head>
<body style="display:none">
<h1>Time out</h1>
</body>
</html>
Michelle Cantin
  • 583
  • 4
  • 15