Skip to content

Instantly share code, notes, and snippets.

View samarpanda's full-sized avatar
👋

Samar Panda samarpanda

👋
View GitHub Profile
@samarpanda
samarpanda / README.md
Created October 6, 2015 12:58
Create simple observable properties

Observable

Working with asynchronous user interface API. Preparing the lego for handling asyn and concurent apis.

const parallelFetch = async (urls) => {
var data = await Promise.all(
urls.map((fetchParams) => {
const { url, options = {} } = fetchParams;
return fetch(url, options).then((response) => response.json());
})
);
return data;
}

New York WebPerf 25th Feb

Talk by @samarpanda

CLS

try {
  var cumulativeLayoutShiftScore = 0;
  const observer = new PerformanceObserver(list => {
@samarpanda
samarpanda / express-etag-fix.md
Last active April 10, 2021 01:29
Express - ETag fix for multiple servers

Express Etag fix (Multiple servers)

Etag uses information from file system stat. Including the modified time similar to nginx & apache. This can't calculate the hash of the contents. Doing so that would require reading the file from the file system twice for every single request scope.

Files usually have slightly different modification timestamp between multiple servers. Similarly apache/nginx would do the same.

Simple way to calculate ETag for the static files:

Increase the speed of HTML5 videos

document.getElementsByTagName('video')[0].playbackRate = 2

Works in frontendmasters

@samarpanda
samarpanda / cumulative-layout-shift.md
Last active June 26, 2020 19:43
Calculative Cumulative Layout Shift(CLS) performance metric

Cumulative layout shift (CLS)

Using web-vitals npm package

import {getCLS} from 'web-vitals';
getCLS(console.log);
@samarpanda
samarpanda / Largest-Contentful-Paint.md
Last active June 23, 2020 17:22
How to measure largest contentful paint

Largest contentful paint

const po = new PerformanceObserver(list => {
  const entries = list.getEntries();
  const lastEntry = entries[entries.length - 1];
  console.log(`LCP is: ${lastEntry.startTime}`);
});
po.observe({ type: 'largest-contentful-paint', buffered: true })