From a6bc37378dc8df6f655dcf7606ff16465f4dabe1 Mon Sep 17 00:00:00 2001 From: William Mikal Ruud Schmidt Date: Tue, 24 Nov 2026 14:05:18 +0100 Subject: [PATCH] Updated docs, ran test-report and README.md --- README.md | 2 +- docs/vm.md | 40 ++++++++++++++++++++++++++++++++++++- frontend/index.html | 2 ++ frontend/public/favicon.svg | 12 +++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 frontend/public/favicon.svg diff --git a/README.md b/README.md index 20259ae..2877dc6 100644 --- a/README.md +++ b/README.md @@ -288,11 +288,11 @@ We follow the principle from the course: measure, set a budget and show the numb - The Apollo cache, so we do not fetch the same data twice. Going back to a wine the user has already seen sends no requests at all. - Debounce on the search field (300 ms). An end-to-end test checks that a whole word sends only one search. - Apache compresses HTML, CSS and JavaScript with gzip. The main JavaScript file goes from 435 kB to 136 kB. +- Apache sends cache headers for the built files. The JavaScript and CSS files have a hash of their content in the name, so the browser keeps them for a year and does not ask for them again (`Cache-Control: public, max-age=31536000, immutable`). `index.html` gets `no-cache`: the browser asks on every visit if it has changed, and gets a short «not changed» answer when it has not. Before, Apache sent only an `ETag`, so the browser had to guess how long to keep each file or ask again for every one. The [VM guide](docs/vm.md#cache-headers) has the configuration. - The main area of every page is at least one screen tall, so the footer does not jump while a page's code loads (see the layout shift below). **Planned:** - Compress the API's JSON responses in Apache. Today they are sent uncompressed. -- Cache headers in Apache for the built files. Their names contain a hash of the content, so they can be cached for a long time. Today Apache sends only an `ETag`, so the browser has to guess how long to keep them or ask again. ### Budget and measurements diff --git a/docs/vm.md b/docs/vm.md index 0be4ebd..ef857f9 100644 --- a/docs/vm.md +++ b/docs/vm.md @@ -247,17 +247,55 @@ ProxyPassReverse "/project2/graphql" "http://127.0.0.1:3001/graphql" FallbackResource /project2/index.html + Header set Cache-Control "no-cache" + + + + FallbackResource disabled + Header set Cache-Control "public, max-age=31536000, immutable" ``` Enable the configuration and check its syntax: ```bash -sudo a2enmod proxy proxy_http +sudo a2enmod proxy proxy_http headers sudo a2enconf project2 sudo apache2ctl configtest ``` +### Cache headers + +The two `Header` lines tell the browser what it can keep between visits: + +- **Files in `assets/`** have a hash of their content in the name, such as `index-BL5R2qxO.js`. A + changed file gets a new name, so the browser can keep each one for a year (`max-age=31536000`) + and never ask again (`immutable`). A returning visitor then downloads no JavaScript or CSS. +- **`index.html`** always has the same name, and it names the hashed files. `no-cache` lets the + browser store it, but makes it ask Apache on every visit if it has changed. Without this, a + visitor could keep an old `index.html` after an update and ask for files that are gone. + +`FallbackResource disabled` makes a missing file in `assets/` give `404`. Without it, Apache would +answer with `index.html` and let the browser keep that answer for a year under the missing file's name. + +The headers do not apply to `/project2/graphql`, because Apache forwards those requests and reads +no file from the directories. + +After a reload, check the headers. Take a file name from the first command's output for the second: + +```bash +curl -s http://localhost/project2/ | grep -o 'assets/index-[^"]*\.js' +curl -sI http://localhost/project2/assets/.js | grep -i cache-control +curl -sI http://localhost/project2/ | grep -i cache-control +curl -sI http://localhost/project2/sok | grep -i cache-control +curl -sI http://localhost/project2/assets/missing.js | head -1 +``` + +The first `Cache-Control` should be `public, max-age=31536000, immutable`, the next two `no-cache`, +and the last line `HTTP/1.1 404 Not Found`. See Apache's +[mod_headers documentation](https://httpd.apache.org/docs/2.4/mod/mod_headers.html#header) and MDN on +[Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control). + If the check reports `Syntax OK`, reload Apache and try a query: ```bash diff --git a/frontend/index.html b/frontend/index.html index 65df8c5..087113b 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -8,6 +8,8 @@ name="description" content="Kork & Krone er et studentdrevet vinregister. Søk blant over 100 000 viner, se hva medstudentene dine mener, og gi din egen dom." /> + + Kork & Krone – vin anmeldt av studenter diff --git a/frontend/public/favicon.svg b/frontend/public/favicon.svg new file mode 100644 index 0000000..725262f --- /dev/null +++ b/frontend/public/favicon.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + +