↑ ↓ select, Enter open, Esc close

Check Cache-Control of all CSS, JS and image files on a page

Adjust the values, the command updates live
user@server
curl -s https://example.com/ | grep -oE '(src|href)="[^"]+\.(css|js|woff2?|jpe?g|png|gif|webp|avif|svg)(\?[^"]*)?"' | cut -d'"' -f2 | sed -E 's#^//#https://#; s#^/#https://example.com/#' | grep '^http' | sort -u | while read -r a; do printf '%-45s %s\n' "$(curl -sI "$a" | grep -i '^cache-control:' | tr -d '\r')" "$a"; done

Extracts stylesheets, scripts, fonts and images from the HTML, turns root-relative paths into absolute URLs and requests the Cache-Control header for each file. Static assets should be cached for a long time (a max-age of one year for versioned files). An empty left column means no Cache-Control is set.

Note: Relative paths without a leading slash and files loaded via CSS or JavaScript are missed. The entry on browser caching headers in the nginx category checks individual URLs.

Also searched as

  • check browser caching for all assets
  • show cache headers of css and js files
  • serve static assets with an efficient cache policy
  • which files are not cached

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.