Shopping cart
A small shop whose cart, discount codes and totals are calculated by the same code on the server and in the browser, which works with and without JavaScript.
All prices are integer cents, so the server and the browser always agree on the total, down to the VAT. With JavaScript, the browser updates the cart right away and sends each change in the background, so the server can store the cart in a signed cookie. Without JavaScript, every click submits a plain HTML form.
The browser's totals are only a preview. Discount codes are secrets, so they never leave the server: applying a code or placing an order is sent to the server, which checks it with its own prices and answers with the new cart. The browser may say which products are in the cart, but never what they cost.
Cart 3
- Subtotal
- €24.10
- Shipping
- €4.90
- Total
- €29.00
- incl. 19% VAT
- €4.63
Add €25.90 more for free shipping.