Skip to content

Instantly share code, notes, and snippets.

View charisTheo's full-sized avatar
⚛️
Reacting

Harry Theo charisTheo

⚛️
Reacting
View GitHub Profile
@PurpleBooth
PurpleBooth / README-Template.md
Last active July 22, 2024 02:29
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@paulirish
paulirish / what-forces-layout.md
Last active July 22, 2024 06:32
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@Rich-Harris
Rich-Harris / service-workers.md
Last active July 10, 2024 17:04
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
@bradtraversy
bradtraversy / webdev_online_resources.md
Last active July 10, 2024 06:26
Online Resources For Web Developers (No Downloading)
@charisTheo
charisTheo / webpagetest-inject-resource-hints.txt
Created July 13, 2020 12:05
Inject resource hints (preload, prefetch, etc) while auditing a page using WebPageTest scripts. Use the textbox in Script (tab) > Enter Script
navigate https://www.example.com
addHeader Link: <images/example-image.jpg>; rel=preload; as=image
addHeader Link: <https://fonts.gstatic.com>; rel=preconnect
addHeader Link: </next-page-navigation>; rel=prefetch
@danieltxok
danieltxok / CLS.js
Created February 17, 2021 11:20
CLS Bookmarklet
javascript:
(function(){
try {
let cls = 0;
const canvas = document.createElement('canvas');
canvas.style.width = '100%';
canvas.style.height = '100%';
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.position = 'absolute';
@danieltxok
danieltxok / LCP.js
Created February 17, 2021 11:21
LCP Bookmarklet
javascript:
new PerformanceObserver((entryList)=>{
for (const entry of entryList.getEntries()) {
let consoleGroup = `%cLCP candidate: ${Math.round(entry.startTime)}ms`;
let styles = '';
if (entry.startTime >= 2500) {
styles = 'color: red;';
}
console.group(consoleGroup, styles);
console.log('Element:', entry.element);
@danieltxok
danieltxok / FID.js
Created February 17, 2021 11:22
FID Bookmarklet
javascript:
new PerformanceObserver((entryList)=>{
for (const entry of entryList.getEntries()) {
const delay = entry.processingStart - entry.startTime;
let consoleGroup = `%cFID value: ${Math.round(delay)}ms`;
let styles = '';
if (delay >= 100) {
styles = 'color: red;';
}
console.group(consoleGroup, styles);
@mmocny
mmocny / inp-devtools-watch.js
Created April 14, 2023 14:12
Add these snippets to DevTools (console) Watch expressions
// max-INP:
(()=>{let o=globalThis;return void 0===o.winp&&(o.winp=0,new PerformanceObserver(n=>{for(let e of n.getEntries()){if(!e.interactionId)continue;o.winp=Math.max(e.duration,o.winp);let r=o=>o<=200?"color: green":o<=500?"color: yellow":"color: red";console.log(`%c[Interaction: ${e.name.padEnd(12)}] %cDuration: %c${e.duration}`,"color: grey; font-family: Consolas,monospace","",r(e.duration))}}).observe({type:"event",durationThreshold:0,buffered:!0})),o.winp})();
// interactionCount
performance.interactionCount;