-
Notifications
You must be signed in to change notification settings - Fork 0
perf: #133 optimize hero image/mobile LCP and configure Apache headers #141
perf: #133 optimize hero image/mobile LCP and configure Apache headers #141
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good PR. The hero is 91–97% smaller, and the Apache config is correct for 2.4. I only looked at what this PR changes on top of #140.
Looks good
- NODE_ENV (from the #136 review): covered now. The runbook has the
Environment=NODE_ENV=productiondrop-in,daemon-reload+ restart, andsystemctl show -p Environment crate-apito check it. - CSP matches what the app needs. I checked each part:
script-src 'self'works becausetheme-init.jsis an external file, the Vite bundle is a module script andindex.htmlhas no inline scripts.style-src 'self'works because Vite emits CSS as separate stylesheet files. The one inline style (visibilityon the artwork credit inAlbumDetailPage) is set by React throughelement.style, and CSP doesn't block that.img-src: the redirect chain forcoverartarchive.org/release-group/…/frontgoes toarchive.organd thenia*.us.archive.org.*.archive.orgmatches subdomains at any depth, so every hop is allowed.font-src/data:: all fonts and both hero images are over Vite's 4 KB inline limit, so none of them becomes adata:URI. Self-hosted woff2 passesfont-src 'self'.connect-src 'self'works because the client falls back to the relative/graphql.
- Apache 2.4:
Header set(notalways) forCache-Controlmeans error responses don't getimmutable.FallbackResourceandDirectoryIndexredirect internally toindex.html, so deep links and a missing asset getno-cache(notimmutable) and the CSP.AddOutputFilterByType DEFLATEworks on proxied responses in 2.4, and both of Yoga's JSON content types are listed.
- Hero markup:
alt=""+aria-hidden,width/heightto avoid layout shift, and the image files really are 1280×720 and 640×360.fetchPriority="high"is fine here.aria-hiddendoesn't remove an image from LCP, and the hero is the largest element above the fold, so it's most likely the LCP element. - License file: updated for both files. The Unsplash License allows crops, and the credit link is still visible.
Should fix (docs only)
- The runner note relies on a setting that isn't in this stack. It says to "rely on the workflow's read-only
GITHUB_TOKENpermissions (contents: read)", butci.ymlon this branch has nopermissions:block. That block comes from #134. Please write "after #134". It also claims more than the token can do. The token only limits the GitHub API. PR jobs run on the VM as the runner user, and that user can write/var/www/html/project2and restartcrate-api. If that's also the user that owns.env, PR code can read it even withchmod 600. I'd write "limits what the token can do on GitHub", not "cannot modify … deployment state". - NODE_ENV does nothing until #129 is merged. Nothing in
server/srcon this stack readsNODE_ENV. TheisProductioncheck is onfix/129-…. One line, "takes effect once #129 is merged", would prevent someone from thinking introspection is already off.
Non-blocking
- The 640w entry in
srcSetis never used. Viewports ≤700px always take thesourceelement, and above 700pxsizes="100vw"always picks 1280w. Pick one: drop thesourceelement and keepsrcSet/sizes, or dropsrcSet/sizesfrom theimg.type="image/webp"on thesourceelement does nothing either, since the fallback is also WebP. - Mobile looks soft on high-DPR phones. The hero is close to square on phones, so
object-fit: coverscales the 640×360 image up a lot. On a 3x phone it's roughly 3.5x. The overlay hides most of it. A portrait-ish mobile crop of about 750×900 would look sharper for a few more KB. - The image is still found late. The
imgonly exists after React renders, so the preload scanner can't see it. The biggest LCP gain here is the smaller file. If you want more, an image preload (rel="preload" as="image"withimagesrcsetandmedia) inindex.htmlwould help, but it needs stable file names (for example inpublic/). A Lighthouse mobile before/after in the PR would show whether that's worth it. theme-init.jsgets noCache-Control. It isn't hashed, so browsers cache it by guessing fromLast-Modified. Adding it to theno-cache<Files>(e.g.<FilesMatch "^(index\.html|theme-init\.js)$">) avoids an old copy after a deploy.- Test the CSP in a browser before turning it on. The
curl -Ichecks only show that the header is there. Loading Discover and an album page with DevTools open, or usingContent-Security-Policy-Report-Onlyfor one deploy, would catch anything I missed.
f9925a6 to
87269e0
Compare
|
Thanks for the careful review, @evenkkl! Rebased onto the updated
Verified locally with |
03da34a to
629879b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, all of it checks out. Approving.
- Runner note: now says plainly that
contents: readonly limits the token on GitHub, and that PR jobs run as the deploy user with access to.env, the web root andsystemctl restart. Good. Note that #137 isn't merged yet, so thepermissions:block isn't onmainuntil it is. - NODE_ENV: the "supported since #129 / PR #136" note is correct. #136 is merged, and
mainhas theisProductioncheck. theme-init.jscaching: theFilesMatchregex is right, the quoted heredoc keeps the backslashes, and the expected output now lists it.- CSP check: the DevTools /
Report-Onlynote is what I was after. - Hero markup: the plain
src+ mobilesourceis correct now, and the tests check thatsrcset/sizes/typeare gone. - Favicon: it's same-origin, so
img-src 'self'covers it, and it removes the/favicon.ico404.
The mobile crop and the image preload from last time are still open, but both were non-blocking. Fine as follow-ups if Lighthouse shows they matter.
…d-delivery docs: #135 final documentation sync, AI reflection, Lighthouse/a11y log, and screenshots
Closes #133
Stacked on #140 (
feat/132-a11y-theme-and-ux-polish→ #138feat/131-client-routing-and-cache→main).What was done
client/src/assets/vinyl-hero.webp,client/src/assets/vinyl-hero-mobile.webp,client/src/assets/vinyl-hero.LICENSE.md):vinyl-hero.webp(1800×2700portrait) — 449,868 B (439.3 KB)vinyl-hero.webp(1280×720landscape, WebP q78) — 39,164 B (38.2 KB) (-91.3%,< 80 KB)vinyl-hero-mobile.webp(640×360landscape, WebP q75) — 13,394 B (13.1 KB) (-97.0%,< 35 KB)client/src/pages/DiscoveryPage.tsx,client/src/App.css,client/src/components/SearchForm.css):::beforehero background with a decorative<picture>element (<source media="(max-width: 700px)" type="image/webp">+<img srcSet="... 640w, ... 1280w" sizes="100vw" width={1280} height={720} alt="" aria-hidden="true" loading="eager" fetchPriority="high" decoding="async">).SearchFormsingle-row down to22.5remwhile preserving>= 2.75remtouch targets, and added a mobile"Browse catalog"jump link to#catalogue.client/src/components/AlbumCover.tsx,client/index.html):referrerPolicy="no-referrer"to external Cover Art Archive artwork<img>elements and<meta name="referrer" content="no-referrer" />toclient/index.html.docs/VM-setup.md):mod_deflateandmod_headers(nomod_expires/mod_brotli):DEFLATE application/json application/graphql-response+jsonfor/graphql,Cache-Control: public, max-age=31536000, immutablefor/project2/assets/,Cache-Control: no-cachefor/project2/index.html, and baseline security headers (X-Content-Type-Options: nosniff,X-Frame-Options: DENY,Referrer-Policy: no-referrer, andContent-Security-Policywithscript-src 'self'compatible with Fix accessibility gaps, add manual light/dark theme toggle, and polish UI/UX #132's external/project2/theme-init.jsandimg-src 'self' https://coverartarchive.org https://archive.org https://*.archive.org).Environment=NODE_ENV=productionforcrate-api.service(paired with Harden GraphQL API & PostgreSQL pool, fix review/cursor bugs, and deduplicate server helpers #129),chmod 600 ~/T19-Project-2/.env, the self-hosted PR runner trust-boundary note (from Run Playwright E2E in CI, expand E2E/Postgres/a11y tests, and harden CI/CD deploy #134), rollback commands, andcurl -I/Accept-Encoding: gzipverification commands.What was tested
pnpm format:check && pnpm lint && pnpm typecheck && pnpm test && pnpm build— all passed with 0 lint warnings and cleanclient/src/generated.client/src/App.test.tsx,client/src/components/AlbumCover.test.tsx, andclient/src/pagination.test.tsx.<= 512,000 B): largest chunkindex-BHPMzRCN.jsis 393,206 B.client/dist/index.htmlincludes<meta name="referrer" content="no-referrer" />and external/project2/theme-init.js(298 B) with zero inline scripts.