Skip to content

Instantly share code, notes, and snippets.

@andydavies
andydavies / index.js
Created January 14, 2021 12:08
Example Cloudflare Worker that removes script preloads
/*
* For more detail see https://andydavies.me/blog/2020/09/22/exploring-site-speed-optimisations-with-webpagetest-and-cloudflare-workers/
* Started from Pat's example in https://www.slideshare.net/patrickmeenan/getting-the-most-out-of-webpagetest
*
* Change site to be site you want to experiment with
*/
const site = 'www.example.com';
async function handleRequest(request) {
@tkadlec
tkadlec / perf-diagnostics.css
Last active June 8, 2023 17:47
CSS used to highlight potential performance issues
:root {
--violation-color: red; /* used for clear issues */
--warning-color: orange; /* used for potential issues we should look into */
}
/* IMAGES */
/*
* Lazy-Loaded Images Check
* ====
@scottjehl
scottjehl / whichones.js
Created August 21, 2020 15:40
which elements are wider than the viewport?
var list = [];
document.querySelectorAll("body *")
.forEach(function(elem){
if(elem.getBoundingClientRect().width > document.body.getBoundingClientRect().width){
list.push(elem.outerHTML.split('>')[0] + '>');
}
});
confirm( "these elements are wider than the viewport:\n\n " + list.join("\n") )
@stowball
stowball / front-end-guidelines.md
Last active April 12, 2024 09:04
Front-End Guidelines
@adactio
adactio / formProgress.js
Created May 29, 2016 15:27
Show a progress bar with every form that has a method of POST. Particularly nice if there's a file upload involved.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
'use strict';
if (!win.XMLHttpRequest || !win.FormData || !win.addEventListener || !doc.querySelectorAll) {
// doesn't cut the mustard.
return;
}
function hijaxForm (formElement) {
var progressBar;
@addyosmani
addyosmani / README.md
Last active April 2, 2024 20:18 — forked from 140bytes/LICENSE.txt
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@scottjehl
scottjehl / noncritcss.md
Last active August 12, 2023 16:57
Comparing two ways to load non-critical CSS

I wanted to figure out the fastest way to load non-critical CSS so that the impact on initial page drawing is minimal.

TL;DR: Here's the solution I ended up with: https://github.com/filamentgroup/loadCSS/


For async JavaScript file requests, we have the async attribute to make this easy, but CSS file requests have no similar standard mechanism (at least, none that will still apply the CSS after loading - here are some async CSS loading conditions that do apply when CSS is inapplicable to media: https://gist.github.com/igrigorik/2935269#file-notes-md ).

Seems there are a couple ways to load and apply a CSS file in a non-blocking manner:

.module {
some: stuff;
&__child {
blah: blah;
}
&--modifier {
modify: me;
}
}
@WebReflection
WebReflection / ietouches.md
Last active December 27, 2015 10:49
moved to a repo instead of a gist
// DISCLAIMER: This is not necessarily good code. It’s just code that I wrote
// as quickly as possible to do each task.
// 1
return 2*i;
// 2
return !(i%2);