Skip to content

Instantly share code, notes, and snippets.

@Nooshu
Nooshu / worker-resource-hints.js
Created March 1, 2021 10:27
Getting a cloudflare worker to add resource hints to the head.
// set the site we are modifying
const site = 'www.example.com';
var resourceHints = `
<link rel="preload" href="/assets/font/font1.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="dns-prefetch" href="https://fonts.gstatic.com/">
<link href="https://cdn.domain.com" rel="preconnect" crossorigin>
`
// do this on a fetch
@Nooshu
Nooshu / index.js
Created January 23, 2021 23:21
Cloudflare worker script for modifying the White House page's HTML and CSS (https://nooshu.github.io/blog/2021/01/23/the-importance-of-font-face-source-order-when-used-with-preload/)
// set the site we are modifying
const site = 'www.whitehouse.gov';
// do this on a fetch
addEventListener('fetch', event => {
const request = event.request
const url = new URL(request.url)
event.respondWith(handleRequest(request))
});
@bvaughn
bvaughn / index.md
Last active April 3, 2024 07:41
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

var event = "Coffee with Ada.";
function describeEvent() {
console.log(event);
}
function calendar() {
var event = "Party at Charles' house.";
describeEvent();
var event = "Coffee with Ada.";
function calendar() {
var event = "Party at Charles' house.";
console.log(event);
}
calendar(); // Logs: "Party at Charles' house."