>_ IzzyLab

Hands-on task

This task is step 14 of the course “New server: setup from scratch”

Compress the scripts and cache the icons

medium~20 min

Before the shop launches, speed up how the frontend is served. In nginx on port 80: turn on gzip for JavaScript (app.js) and SVG (logo.svg), and put a Cache-Control header valid for at least 30 days on js, css and svg static files. The home page must still open.

What you'll practise:
  • nginx
  • gzip_types
  • expires
  • cache-control
  • mime.types

Topic breakdown

Serving static files gets faster with two independent nginx settings. Compression (gzip) shrinks text responses on the fly; by default it applies only to HTML, and other formats are listed in gzip_types by MIME type — SVG is text too (XML) and compresses well, while already compressed PNG and JPEG don't. Caching lets the browser keep the file and not ask the server again: the Cache-Control: max-age=… header is conveniently set with the expires directive inside a location that catches the right extensions. After editing, the config is checked with nginx -t and reloaded.

What's checked

  1. app.js is served gzipped
  2. logo.svg is served gzipped
  3. js and svg have a Cache-Control of at least 30 days
  4. the home page opens

What it looks like