Skip to content

Instantly share code, notes, and snippets.

@voxpelli
Created February 22, 2017 19:29
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 voxpelli/0927bb9d53d027d924728ed7382c2fb6 to your computer and use it in GitHub Desktop.
Save voxpelli/0927bb9d53d027d924728ed7382c2fb6 to your computer and use it in GitHub Desktop.

Test case for duplicate downloads of Link Preloads

  1. Download package.json and single-preload.js and put into same folder
  2. Run npm install
  3. Run node single-preload.js
  4. Visit http://127.0.0.1:4000/ using Safari Technology Preview 24 with the Link Preload experimental feature activated
  5. Check the Network tab of the web development tools. See two style.css that's loaded
{
"name": "preload-testcase",
"version": "1.0.0",
"description": "",
"main": "single-preload.js",
"author": "Pelle Wessman <pelle@kodfabrik.se> (http://kodfabrik.se/)",
"license": "MIT",
"dependencies": {
"express": "^4.14.1"
}
}
'use strict';
const app = require('express')();
app.get('/style.css', (req, res) => {
res.type('css');
res.send('body { background: blue; }')
});
app.get('/', (req, res) => {
res.set('Link', '</style.css>; rel=preload; as=style');
res.send(`<!DOCTYPE html>
<html id="root-element" class="no-js">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="/style.css" />
</head>
<body>
<h1>Single preload</h1>
<p>Test case to detect double loading resource through rel-preload</p>
</body>
</html>
`);
});
app.listen(4000, function () {
console.log('Example app listening on port 4000!')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment