Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kork & Krone

**Last updated:** 19 November 2026
**Last updated:** 23 November 2026
**Submission:** 4 (working system, ready for feedback on every aspect)
**Status:** In progress. See [Status for submission 4](#status-for-submission-4).

Expand Down Expand Up @@ -285,26 +285,58 @@ We follow the principle from the course: measure, set a budget and show the numb
- Search, filtering, sorting and pagination run in the database. A page returns at most 50 wines.
- The rating average is stored on the wine, so no query counts millions of rows.
- DataLoader batches the lookups a page needs, so a page of wines runs one query per field instead of one per wine.
- The Apollo cache, so we do not fetch the same data twice.
- 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.
- 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:**
- Cache headers in Apache.
- 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

Measured on 23 November 2026 on the VM, with the Full dataset (100 646 wines). The bytes are what
actually went over the network (`transferSize` from the browser's Resource Timing API), so compressed
files count at their compressed size. A first visit is with an empty cache, a repeat visit is a reload
afterwards.

| Metric | Budget | Measured | Date | How we measure |
|---|---|---|---|---|
| JavaScript on the landing page (gzip) | Less than 150 kB | 155,05 kB (over budget after adding Apollo Client) | 7 Nov 2026 | Sum of the gzip sizes from `npm run build` for the files the landing page loads |
| Data transferred when loading the landing page | Less than 300 kB | Not measured yet | | Chrome DevTools, Network tab, cache disabled, on the VM |
| Data transferred in a fixed search scenario | Less than 500 kB | Not measured yet | | Same method. Needs the search page |
| Lighthouse (mobile) | Performance at least 90, accessibility 100 | Performance 39, accessibility 100, best practices 100, SEO 100 | 30 Oct 2026 | Lighthouse in Chrome DevTools, incognito, against the VM |
| CO2 per visit | Not decided | Not measured yet | | CO2.js (Sustainable Web Design model) with the transferred bytes |

The search scenario is: open the landing page, search for "riesling", filter on red wine, and load one more page of results.
Lighthouse performance was low mainly because Apache did not compress files or set cache headers at the time,
and because the test was run over VPN. These are the "before" numbers. Compression is now on, and we will measure again.
| JavaScript on the landing page (gzip) | Less than 150 kB | 163.6 kB (over budget) | 23 Nov 2026 | Transferred JavaScript on the VM, from Resource Timing |
| Data transferred, landing page | Less than 300 kB | 172.5 kB in 20 requests on the first visit, 6.6 kB on a repeat visit | 23 Nov 2026 | Resource Timing on the VM |
| Data transferred, wine page | Less than 300 kB | 173.8 kB on the first visit, 14.6 kB on a repeat visit, 0 kB back to the same wine within the app | 23 Nov 2026 | Same method |
| Data transferred in a fixed search scenario | Less than 500 kB | 335.3 kB: 289.8 kB of code and styles, and 45.5 kB from the API in 7 requests | 23 Nov 2026 | Same method, through the whole scenario |
| Lighthouse (mobile) | Performance at least 90, accessibility 100 | On the VM: performance 78, accessibility 100, best practices 74, SEO 100 on the landing page, and 79 / 100 / 74 / 100 on the search page | 23 Nov 2026 | Lighthouse in Chrome DevTools, incognito, against the VM |
| Cumulative Layout Shift (CLS) | Less than 0.1 | 0.356 on the VM before the fix. 0.021 on the landing page and 0.005 on the search page after it, measured locally | 23 Nov 2026 | Lighthouse, as above |
| CO2 per visit | Less than 0.1 g | Landing page 0.026 g (0.001 g repeat visit), wine page 0.026 g (0.002 g repeat visit), the whole search scenario 0.051 g | 23 Nov 2026 | CO2.js 0.16, Sustainable Web Design model v4 (`perVisit`), with the transferred bytes |

The search scenario is: open the landing page, search for "riesling", filter on white wine, and load one
more page of results. We first planned red wine, but there are only 7 red rieslings, too few for a second
page, so we changed it to white wine.

**What the numbers show.** A first visit is mostly code: 163.6 of the 172.5 kB on the landing page is
JavaScript. After that, the browser keeps the code and Apollo keeps the data, so a repeat visit costs
6.6 kB, and moving around inside the app costs only the data for what is new. The whole search scenario,
with two pages of results, stays well under its budget.

**JavaScript over budget.** The landing page has been over the 150 kB budget since we added Apollo
Client. Lighthouse reports 46 kB of JavaScript that the landing page loads without using. We keep the
budget rather than raising it, and look at splitting out more of the code that only other pages need.

**Layout shift.** Lighthouse showed that the low performance score came mainly from Cumulative Layout
Shift: 0.356, where under 0.1 is good. While a page's code loaded, only «Laster …» was in the main area,
so the footer sat high up and was pushed down when the page came. We gave the main area a minimum height
of one screen, and CLS went down to 0.021 on the landing page and 0.005 on the search page. These after
numbers are from a local build (`npm run build` and `npm run preview`), because the fix was not on the VM
yet. Local runs have no network between the browser and the server, so we only compare CLS from them,
not the other numbers.

**Best practices 74.** The VM serves the site over HTTP, not HTTPS, which Lighthouse marks down. The same
build gets 96 locally, where Chrome treats `localhost` as secure.

**Earlier numbers.** On 30 October, Lighthouse performance was 39, mainly because Apache did not
compress files at the time and the test was run over VPN. Turning on compression took it to 78.

## Testing

Expand Down Expand Up @@ -409,7 +441,8 @@ Claude and ChatGPT are the main models used. The usecases for the AI tools are a
- [x] Wishlist stored in the backend, so it follows the user between devices.
- [ ] Calmer landing page: less text, a separate «Om» page, and a burger menu on mobile.
- [ ] CI, an enforced coverage threshold, and eslint-plugin-jsx-a11y.
- [ ] Measure sustainability and fill in the budget table.
- [x] Measure sustainability and fill in the budget table.
- [ ] Compress API responses and set cache header in Apache.
- [ ] Screen reader test and a written reflection on the use of AI.
- [ ] Prettier and ESLint in the backend, like in the frontend.

Expand All @@ -430,7 +463,6 @@ Claude and ChatGPT are the main models used. The usecases for the AI tools are a
- The cursors in the API hold an offset, which is slower deep into large results. To be solved together with the larger dataset.
- The database and its user are still called `vinmonopolet` and `vinmonopolet_app`, from before we switched dataset. Renaming would mean everyone rebuilding their database, so we kept the names.
- Reviews from before login have no account and are shown as «Anonym student». The old `student` table they belong to will be removed later.
- One e2e test, checking «Rødvin» in the filter dialog on mobile, fails since the error handling changes. Tracked in its own issue.

<!--
Remove known issues as they are fixed.
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/layout/AppLayout.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
transform: none;
}

/*
* At least one screen tall, so the footer starts below the fold. Without it, the footer sat
* just under "Laster ..." while a page's code loaded, and was pushed down when the page came:
* Lighthouse measured that as a layout shift of 0.34 (CLS, where under 0.1 is good).
*/
.main {
display: block;
min-height: 100vh;
min-height: 100dvh;
}

.main:focus {
Expand Down