Skip to content

Instantly share code, notes, and snippets.

@willfrew
Created June 27, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willfrew/d0d0938bec20f81f1c3ab2b6b294b6e6 to your computer and use it in GitHub Desktop.
Save willfrew/d0d0938bec20f81f1c3ab2b6b294b6e6 to your computer and use it in GitHub Desktop.
Iframe caching test
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
(function() {
// 1 or 2
let i = Math.round(Math.random()) + 1
console.log(`Loading iframe ${i}`);
let iframe = document.createElement('iframe');
iframe.src = `./iframe${i}.html`;
iframe.name = 'consistent';
document.body.appendChild(iframe);
})();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script>
console.log('IFRAME 1');
</script>
</head>
<body></body>
</html>
<!DOCTYPE html>
<html>
<head>
<script>
console.log('IFRAME 2');
</script>
</head>
<body></body>
</html>
{
"name": "iframe-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"static-server": "^2.2.1"
}
}
var StaticServer = require('static-server');
var server = new StaticServer({
rootPath: '.', // required, the root of the server file tree
port: 1337, // required, the port to listen
cors: '*', // optional, defaults to undefined
});
server.on('request', function (req, res) {
let cacheControl = (/host.html/.test(req.path))
? 'no-cache, no-store, must-revalidate'
: 'public, max-age=31536000'
res.headers = {
...res.headers,
'Cache-Control': cacheControl,
};
});
server.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment