Skip to content

Instantly share code, notes, and snippets.

@stephenmathieson
Last active May 20, 2021 20:06
Show Gist options
  • Save stephenmathieson/efde446cd0a52f4a13596b00eafc8555 to your computer and use it in GitHub Desktop.
Save stephenmathieson/efde446cd0a52f4a13596b00eafc8555 to your computer and use it in GitHub Desktop.
Little node app with a realllllyyy slow iframe
const http = require('http')
const server = http.createServer((req, res) => {
console.log('%s - %s', req.method, req.url)
if (req.url === '/frame') {
setTimeout(() => {
res.setHeader('Content-Type', 'text/html')
res.write(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Frame</title>
</head>
<body>
<h1>I'm a frame.</h1>
<h2>Below are a lot of content nodes</h2>
`)
for (let i = 0; i < 100000; i++) {
res.write(`
<div id="node_${i}>
<nav>
<ul>
<li>
<span>
<a href="http://google.com">
google.com
</a>
</span>
</li>
<li>
<span>
<a href="http://wikipedia.org">
wikipedia.org
</a>
</span>
</li>
</ul>
</nav>
</div>
`)
}
res.write('</body></html>')
res.end()
}, 5000)
} else {
res.setHeader('Content-Type', 'text/html')
res.write(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>I'm document with an iframe.</h1>
<iframe src="/frame" title="frames r cool"></iframe>
</body>
</html>
`)
res.end()
}
})
server.listen()
server.on('listening', () => {
const addr = server.address()
console.log(`Server listening at http://localhost:${addr.port}`)
})
server.on('error', error => {
throw error
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment