#!/bin/bash | |
# Configuration | |
ENV=local | |
PROJECT=demo | |
IMAGE=redis:7.4.0 | |
CNAME=redis-$ENV-$PROJECT | |
PORT=6379 | |
DATA_DIR=$PWD/data |
Quick file serving with lightweight & efficient webserver using nginx:1.25-alpine
Quick project aims to demonstrate the creation, deployment of a lightweight & efficient web server using Nginx running on an Apline Linux based Docker container. The project serve static files from any mounted folder, making an ideal solution for hosting simple website, front-end applications, or any content that needs to be served from a folder / local system.
- Container name
CNAME=nginx-8080
- Nginx image is used from dockerhub
function getRandomCharacter(charset = "" ){ | |
const randomIndex = Math.floor(Math.random() * charset.length); | |
return charset.charAt(randomIndex); | |
} | |
function generatePassword(length) { | |
const charsetAlphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$?"; | |
// const charsetNumbers = "0123456789"; | |
// const specialCharacters = "!@#$?" | |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
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; | |
} |
I wonder if i can see all the lcp elements instead of getting the eventual lcp element from the performance panel. Below script higlights all lcp elements available on the page. After running the script in console / source - snippet it highlight by a dotten blue line for all lcp elements. This uses browser's PerformanceObserver API to get all lcp elements.
By @samarpanda
/**
* PerformanceObserver
*/
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:
- We profiled quikr.com/jobs using wpt
- Preconnect resource hint crossorigin attribute
- Discussion on resource benefited from preconnect?
- WebPageTest and cloudflare workers - By Andy Davies - London webperf meetup
- Cumulative layout shift what it measures, when it works and how to use it - By Tammy everts
- Akamai real user measurement solution - mPulse
- Speedcurve real user measurement - lux 1