Add Last-Modified/ETag and 304 responses for static files and media

Open
#35 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
75/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js

Research direction

Read server.js:51-66, media.js:21-36, and the existing request tests in test/server.test.js; trace how static files and showcase videos are served. Add the shared validators(stats) helper described in the issue and cover conditional and range requests. Done when tests show 304 responses for repeated requests to /demo.html and a showcase .mp4, and a stale If-Range gets 200.

Written by the indexing model from the issue text.

Description

help wanted performance

serveFile() (server.js:51-66) sends no caching headers and ignores conditional requests. So every visit re-downloads public/_vendor/gsap.min.js, mp4-muxer.js, the reference JPEGs and the JSON files in full.

streamVideo() (media.js:21-36) has the opposite problem. It sets Cache-Control: private, max-age=3600 but no validator, so after you re-import or run npm run showcase the browser can play the old video for up to an hour.

Expected: both paths send Last-Modified (from the stat mtime) and a weak ETag (size plus mtime). A matching If-None-Match or If-Modified-Since returns 304 with no body. For media, use Cache-Control: no-cache so the browser checks again on every load and then gets a cheap 304. Handle If-Range so a range request on a changed file gets the full 200.

Fix direction: add a small validators(stats) helper in media.js, use it in both functions, and keep serveFile's path checks as they are.

Done when new tests in test/server.test.js show a 304 for a repeated request with If-None-Match to /demo.html and to a showcase .mp4. A stale If-Range should get a 200.

Dominant language
HTML
Stars
1.2k
Forks
109
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from blixvip/NullMotion

All issues in blixvip/NullMotion

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.