This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function measureEventPerformance(event) { | |
const lag = performance.now() - event.timeStamp; | |
console.log(`Event took: ${lag} ms`); | |
} | |
// Usage | |
const submitButton = document.querySelector('button[type="submit"]'); | |
submitButton.addEventListener('click', (event) => { | |
// Event listener logic here... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function Queue(){ | |
this.push = function(){ | |
for (var i = 0, len = arguments.length; i < len; i++){ | |
if (typeof arguments[i] !== 'function'){ | |
throw new TypeError('Argument must be a function.') | |
} | |
arguments[i]() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function overrideOnce(object, method, callback){ | |
// override method with original as argument | |
object[method] = (function(original){ | |
return function(){ | |
// store whatever callback does | |
var result = callback.apply(this, arguments); | |
// restore method | |
object[method] = original; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* criticalCSS by @dansajin. based on @scottjehl's criticalcss.js | |
* run this in a browser console or create a bookmarklet. | |
* lists rules per css file. | |
* does not include cross origin css files and inline css. | |
*/ | |
(function(){ | |
var sheets = document.styleSheets, | |
host = window.location.host, | |
maxTop = 1200, |