Skip to content

Instantly share code, notes, and snippets.

@cvazac
cvazac / fetchLinks.js
Last active September 14, 2016 22:14
@cvazac
cvazac / taskQueue.js
Last active September 14, 2016 22:09
(function() {
var tasks = []
function run() {
tasks.push(Array.prototype.slice.call(arguments))
waitThenRun()
}
function waitThenRun() {
requestAnimationFrame(function() {
if (tasks.length === 0) {
return
@cvazac
cvazac / natives.js
Last active November 30, 2017 20:28
;(function() {
function getNatives(objects) {
if (typeof objects === 'string') {
objects = [objects]
}
var natives = {}
if (objects.length) {
var iframe = document.createElement('iframe')
iframe.style.display = 'none'
@cvazac
cvazac / checkNatives.js
Created April 26, 2017 16:41
checkNatives
function isNativeFunction(fn) {
return typeof fn === 'function' && fn.toString && !fn.hasOwnProperty('toString') &&
/\[native code\]/.test(String(fn))
}
function checkNatives(fns) {
var results = []
for (var i = 0; i < fns.length; i++) {
results[i] = {
fn: fns[i],
native: isNativeFunction(fns[i])
(function() {
if (window !== top) return;
const bucketSize = 500, threshold = 30, stamps = []
function measureFps() {
const now = performance.now()
if (stamps.length) {
while (now - stamps[0] > bucketSize) {
stamps.shift()
}
const query = `
CREATE TEMPORARY FUNCTION getHeaders(payload STRING)
RETURNS STRING
LANGUAGE js AS """
try {
var $ = JSON.parse(payload);
var headers = $.response.headers;
var st = headers.find(function(e) {
return e['name'].toLowerCase() === 'server-timing'
});
!(function() {
const nativePO = window.PerformanceObserver
const interfaces = {
resource: 'PerformanceResourceTiming',
longtask: 'PerformanceLongTaskTiming',
// etc.
}
const polyfills = {
longtask: LongTaskPolyFill
// etc.
!(function() {
const nativePO = window.PerformanceObserver
const polyfills = {
longtask: LongTaskPolyFill
// etc.
}
window.PerformanceObserver = (callback) => {
let po, registeredPolyFills = []
const observe = function(options) {
@cvazac
cvazac / cached-in-browser.js
Last active November 28, 2017 03:41
Heuristic to identify resources that were cached in the browser
function cachedInBrowser(resourceTimingEntry) {
if (resourceTimingEntry.requestStart) {
// has permissive Timing-Allow-Origin response header
return resourceTimingEntry.transferSize === 0
}
// because.... physics?
return resourceTimingEntry.duration < 30
}
(function() {
let userThinkTime = 0
;['alert', 'confirm', 'prompt'].forEach(function(methodName) {
window[methodName] = (function(method) {
return function () {
userThinkTime -= performance.now()
var returnValue = method.apply(window, arguments)
userThinkTime += performance.now()
return returnValue