The response may be stored only in the browser's cache
Cache-Control Headers
no-cache
The response may be stored by any cache, even if the response is normally non-cacheable. However, the stored response MUST always go through validation with the origin server first before using it.
no-store
The response may not be stored in any cache. Note that this will not prevent a valid pre-existing cached response being returned. Clients can set max-age=0
Etag
Check the file hash to see if it has changed from the cached version
Most servers automatically add etag for you to static assets
304 Not Modified
etag: "2d9d-5a31a59c7b011-gzip"
"There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors."
— @codinghorror
Apache Cache with mod_expires
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
</IfModule>
Apache Cache with mod_headers
<ifModule mod_headers.c>
# One year for image and video files
<filesMatch ".(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
# One month for JavaScript and PDF files
<filesMatch ".(js|pdf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
# One week for CSS files
<filesMatch ".(css)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
</ifModule>
The goal is you only use this command: lhci autorun
But really it is running these: lhci collect --url https://pixotech.com lhci open upload --target lhci --token 2348-3829 --serverBaseURL https://example.com
new-project
? What is the URL of your LHCI server? https://username:password@lighthouse-ci.pixodev.net
? What would you like to name the project? basic-auth-test
? Where is the project's code hosted? nowhere
? What branch is considered the repo's trunk or main branch? main
Created project basic-auth-test (5a4060d1-f122-422f-80b8-5d6e74926965)!
Use build token b54c8ac2-123-123-123-ff3c04e988e0 to add data.
Use admin token KkGbJNDbEqLsdfsvWilLKdlmG2sY5Il5cocyKEgR to manage data. KEEP THIS SECRET!
PLEASE save both tokens somewhere
When to use lhci instead of lighthouse
You want automated runs of lighthouse with a config file running the entire process
You can still script lighthouse
You want to upload to a particular destination
.lighthouserc.json in the root directory (or .yaml or .js)
name: Performance Audit
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install
run: |
npm ci
- name: Build
run: |
npm run build
- name: Run Lighthouse CI
run: |
npm install -g @lhci/cli@0.3.x
lhci autorun
DNS
Check your site
Penalty you pay on first load of each sub/domain
Fast sites lookup in ~20ms
Normal sites lookup less than ~100ms
dig pixotech.com mac linux nslookup -debug pixotech.com win
; <<>> DiG 9.10.6 <<>> pixotech.com
;pixotech.com. IN A
pixotech.com. 77 IN A 52.34.48.14
;; Query time: 82 msec
$ httpstat steve.zazeski.com
Connected to 3.13.92.225:80 from 192.168.1.194:41286
HTTP/1.1 301 Moved Permanently
Server: openresty
Date: Mon, 12 Apr 2021 23:30:21 GMT
Content-Type: text/html
Content-Length: 166
Connection: keep-alive
Location: https://steve.zazeski.com/
Strict-Transport-Security: max-age=63072000;includeSubDomains; preload
X-Served-By: steve.zazeski.com
Body stored in: /tmp/tmpxaqmzk5i
DNS Lookup TCP Connection Server Processing Content Transfer
[ 73ms | 25ms | 35ms | 1ms ]
| | | |
namelookup:73ms | | |
connect:98ms | |
starttransfer:133ms |
total:134ms
DNS - CNAMES
All DNS queries recurse until they end in A / AAAA record
build.pixotech.com. 299 IN CNAME on-premise-docker-swarm.pixodev.net.
on-premise-docker-swarm.pixodev.net. 59 IN CNAME icarus.pixodev.net.
icarus.pixodev.net. 59 IN A 173.167.185.184
;; Query time: 219 msec