Skip to content

Instantly share code, notes, and snippets.

@paulirish
Last active January 14, 2024 13:22
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save paulirish/a76ac17fc211b019e538c09d8d827691 to your computer and use it in GitHub Desktop.
Save paulirish/a76ac17fc211b019e538c09d8d827691 to your computer and use it in GitHub Desktop.
Demo of server timing values. visualized in chrome devtools
// see for screenshot:
// https://twitter.com/paul_irish/status/829090506084749312
const http = require('http');
function requestHandler(request, response) {
const headers = {
'Server-Timing': `
sql-1;desc="MySQL lookup Server";dur=100,
sql-2;dur=900;desc="MySQL shard Server #1",
fs;dur=600;desc="FileSystem",
cache;dur=300;desc="Cache",
other;dur=200;desc="Database Write",
other;dur=110;desc="Database Read",
cpu;dur=1230;desc="Total CPU"
`.replace(/\n/g, '')
};
response.writeHead(200, headers);
response.write('');
return setTimeout(_ => {
response.end();
}, 1230)
}
http.createServer(requestHandler)
.listen(8082)
.on('error', console.error);
@brandonsturgeon
Copy link

Nice job!

@paulirish
Copy link
Author

paulirish commented Apr 19, 2017

:D

image

@paulirish
Copy link
Author

updated for the latest version of the spec.

@chkal
Copy link

chkal commented Mar 11, 2018

Does Chrome implement the latest version of the spec or the format from the original tweet?

@chkal
Copy link

chkal commented Mar 11, 2018

Answering my own question: Chrome 65 supports the latest version of the spec (new header format as shows in this gist), Chrome 64 just the old header format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment