im
Clone
https://git.tahinli.com/Tahinli/im.git
0 watching0 forksRustAGPL-3.0542.8 KiBb9f0726Tahinli27 days ago34 commits
| 1 | //! The static files of the UI, compiled into the binary and served from `/assets/`. |
| 2 | //! |
| 3 | //! The CSS is compiled from `style/` by `build.rs`. The scripts and the offline page are in |
| 4 | //! `crates/im-web/assets/`. Each link to a file that changes with a build carries the first 12 |
| 5 | //! hex digits of its SHA-256 as `?v=`, so a changed file gets a new URL and an unchanged one keeps |
| 6 | //! its cache entry. Files whose URL does not change (the service worker and the offline page) are |
| 7 | //! served with `no-cache`. |
| 8 | |
| 9 | use Result; |
| 10 | use ; |
| 11 | |
| 12 | /// Link to the stylesheet, with its content version. |
| 13 | pub const MAIN_CSS_HREF: &str = concat!; |
| 14 | |
| 15 | /// Link to the script that makes navigation soft and drives the live pages. |
| 16 | pub const NAV_JS_HREF: &str = concat!; |
| 17 | |
| 18 | /// Link to the script of individual pages. |
| 19 | pub const PAGES_JS_HREF: &str = concat!; |
| 20 | |
| 21 | const MAIN_CSS: &str = include_str!; |
| 22 | const NAV_JS: &str = include_str!; |
| 23 | const PAGES_JS: &str = include_str!; |
| 24 | const OFFLINE_HTML: &str = include_str!; |
| 25 | const SW_JS: &str = include_str!; |
| 26 | |
| 27 | /// A content-versioned file. The URL changes with the bytes, so the browser may keep it for a year. |
| 28 | const IMMUTABLE: &str = "public, max-age=31536000, immutable"; |
| 29 | |
| 30 | /// A file whose URL stays the same across builds. The browser must ask again each time. |
| 31 | const REVALIDATE: &str = "no-cache"; |
| 32 | |
| 33 | /// The status, headers and body of an asset answer. |
| 34 | type Asset = ; |
| 35 | |
| 36 | /// Builds the answer for one asset: the content type and the cache policy. |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | /// `GET /assets/main.css`. |
| 45 | |
| 46 | async |
| 47 | |
| 48 | |
| 49 | |
| 50 | /// `GET /assets/nav.js`. |
| 51 | |
| 52 | async |
| 53 | |
| 54 | |
| 55 | |
| 56 | /// `GET /assets/pages.js`. |
| 57 | |
| 58 | async |
| 59 | |
| 60 | |
| 61 | |
| 62 | /// `GET /assets/offline.html`. Also precached by the service worker. |
| 63 | |
| 64 | async |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// `GET /assets/sw.js`. It is served at the root scope, which needs the `Service-Worker-Allowed` |
| 69 | /// header; without it the browser would limit the worker to `/assets/`. |
| 70 | |
| 71 | async |
| 72 | |
| 73 | |
| 74 | |
| 75 |