fix send Cache-Control no-cache on embedded assets

The stylesheet and client JS carry no version in their URLs and change on every rebuild, so browsers served stale copies. Revalidate each load.

Commit
dd23882d66c65d3b15393d3a34c255406d9a72b3
Author
Marius Peter <dev@marius-peter.com>
Author date
Committer
Marius Peter <dev@marius-peter.com>
Committer date
lib/web/handlers_assets.ml
index 48ee7d92..931d1a48 100644..100644
@@ -13,14 +13,20 @@
13 13 | Some script -> script
14 14 | None -> failwith "Embedded workout client is missing"
15 15
16 Added: (* Embedded assets change whenever the binary is rebuilt, and the URLs carry no
17 Added: version, so [no-cache] makes the browser revalidate on every load rather than
18 Added: serve a stale copy after a deploy. Cheap: the payloads are small. *)
19 Added: let asset_headers content_type =
20 Added: [ ("Content-Type", content_type); ("Cache-Control", "no-cache") ]
21 Added:
16 22 let routes =
17 23 [
18 24 Dream_html.get Routes.stylesheet (fun _ ->
19 25 Dream.respond
20 Removed: ~headers:[ ("Content-Type", "text/css; charset=utf-8") ]
26 Added: ~headers:(asset_headers "text/css; charset=utf-8")
21 27 stylesheet);
22 28 Dream_html.get Routes.workout_client (fun _ ->
23 29 Dream.respond
24 Removed: ~headers:[ ("Content-Type", "application/javascript; charset=utf-8") ]
30 Added: ~headers:(asset_headers "application/javascript; charset=utf-8")
25 31 workout_client);
26 32 ]