Skip to content

Instantly share code, notes, and snippets.

View ethangardner's full-sized avatar

Ethan Gardner ethangardner

View GitHub Profile
@pmeenan
pmeenan / wpt-hints.md
Last active March 18, 2023 16:48
Testing Priority Hints with WebPageTest

Priority Hints is rolling out to Chrome in the 101 release which is currently available in the Dev/Beta channel of Chrome and available in WebPageTest when using the Chrome Canary browser selection.

To make it easier to experiment with priority hints (particularly for LCP images) without making production changes, I set up a couple of public Cloudflare Workers that can be used dynamically with WebPageTest to inject priority hints into existing pages and to preload arbitrary images when combined with WebPageTest's overrideHost script command.

Injecting Priority Hints

There is a cloudflare worker at hint.perf.workers.dev that will take a CSS selector from the x-hint HTTP header and add fetchpriority=high to any elements in the HTML that match the selector. The easiest way to experiment with this is to use Chrome's dev tools locally, identify the element that hosts the imag

@DavidWells
DavidWells / github-proxy-client.js
Last active June 27, 2024 14:52
Full Github REST api in 34 lines of code
/* Ultra lightweight Github REST Client */
// original inspiration via https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const token = 'github-token-here'
const githubClient = generateAPI('https://api.github.com', {
headers: {
'User-Agent': 'xyz',
'Authorization': `bearer ${token}`
}
})
@DavidWells
DavidWells / javascript-proxy-as-rest-client.js
Last active May 12, 2024 14:24
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
@jakub-g
jakub-g / async-defer-module.md
Last active July 15, 2024 12:12
async scripts, defer scripts, module scripts: explainer, comparison, and gotchas

<script> async, defer, async defer, module, nomodule, src, inline - the cheat sheet

With the addition of ES modules, there's now no fewer than 24 ways to load your JS code: (inline|not inline) x (defer|no defer) x (async|no async) x (type=text/javascript | type=module | nomodule) -- and each of them is subtly different.

This document is a comparison of various ways the <script> tags in HTML are processed depending on the attributes set.

If you ever wondered when to use inline <script async type="module"> and when <script nomodule defer src="...">, you're in the good place!

Note that this article is about <script>s inserted in the HTML; the behavior of <script>s inserted at runtime is slightly different - see Deep dive into the murky waters of script loading by Jake Archibald (2013)

@ole-boss
ole-boss / Big Query Google Analytics sessions export including site speed metrics.sql
Last active June 13, 2020 14:41
This script helps you creating sessions from Google Analytics raw data on hit level in Google Big Query. The export will also include some metrics related to site speed based on Google's Latency Tracking KPIs.
SELECT
first_sessions.sid AS sessionId,
visitorId,
first_transactions.transactionId AS transactionId,
timestamp,
deviceCategory,
landingPage,
pageviews,
timeOnSite,
channel,
@mvital
mvital / excerpt-as-instant-article-subtitle.php
Created January 11, 2017 15:42 — forked from webdados/excerpt-as-instant-article-subtitle.php
Use WordPress post excerpt as Facebook Instant Article subtitle
<?php
/* Instant Articles (https://wordpress.org/plugins/fb-instant-articles/) - Use post excerpt as subtitle */
add_filter( 'instant_articles_subtitle', 'hf_instant_articles_subtitle' );
function hf_instant_articles_subtitle( $subtitle ) {
$excerpt = get_the_excerpt();
if ( trim($excerpt)!='' ) $subtitle = trim($excerpt);
return $subtitle;
}
@milon
milon / elasticsearch_on_homestead.md
Last active November 23, 2022 15:18
Install Elasticsearch on Laravel Homestead

Install Elasticsearch on Laravel Homestead

Install Java

sudo apt-get install openjdk-7-jre-headless -y

Download & install the Public Signing Key

wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -
@mdesanti
mdesanti / build-and-deploy.sh
Created February 14, 2016 18:24
Build and upload code to lambda
#!/bin/bash
echo 'Zipping folders for save function'
zip -r Save.zip node_modules save.js
echo 'Zipped... uploading to AWS'
aws lambda update-function-code --region us-east-1 --function-name saveEmailSubscriptor --zip-file fileb://./Save.zip --profile your-profile
echo 'Zipping folders for list function'
zip -r List.zip node_modules list.js
echo 'Zipped... uploading to AWS'
aws lambda update-function-code --region us-east-1 --function-name listEmailSubscriptors --zip-file fileb://./List.zip --profile your-profile
@jakub-g
jakub-g / _1_"script async defer" blocks "load" event.md
Last active August 22, 2023 10:10
Beware of "script async defer" blocking HTML "load" event

Beware of <script async defer> blocking HTML "load" event

2015.10.07 t

On the importance of simulated latency testing, and bulletproofing your page from the third-party JS load failures

TL;DR