Skip to content

Commit

Permalink
overhaul HTTP serving and caching
Browse files Browse the repository at this point in the history
* use content-hashed paths for static resources (except the top-level
  request), with immutable Cache-Control headers. This should improve
  cache behavior in both directions: avoid preventable HTTP requests and
  cause immediate refresh when needed. I had some staleness when
  browsing with my phone.

* set up the favicons properly while I'm at it (closes #50). I used the
  convenient favicons-webpack-plugin to build everything from a .svg.
  I've hit an error similar to lovell/sharp#1593 at least once though so
  I might change my mind about that part if it continues to be
  problematic.

* use http-serve's new directory traversal code for static file serving.
  This removes the odd behavior where files that weren't present at
  server startup couldn't be served. (I wasn't comfortable switching to
  the content-hashed paths before doing this.) It also means the static
  files can be served compressed. JSON API responses were already served
  compressed, so this closes #25.

* for a given API URL, decide if we want it to be cached or not
  server-side. Stop using jQuery's kludgy cache-defeating _=<timestamp>
  URL parameter. I might start setting etags on some of these things
  and could serve 304 Not Modified responses if it's genuinely
  unmodified.
  • Loading branch information
scottlamb committed May 30, 2020
1 parent 88fe6e5 commit 45abeb2
Show file tree
Hide file tree
Showing 15 changed files with 1,768 additions and 314 deletions.
81 changes: 6 additions & 75 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ffmpeg = { package = "moonfire-ffmpeg", path = "ffmpeg" }
futures = "0.3"
fnv = "1.0"
http = "0.2.0"
http-serve = "0.2.0"
http-serve = { git = "https://github.com/scottlamb/http-serve", branch = "dir", features = ["dir"] }
hyper = "0.13.0"
lazy_static = "1.0"
libc = "0.2"
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"author": "Scott Lamb <[email protected]>",
"author": {
"name": "Scott Lamb",
"email": "[email protected]",
"url": "https://www.slamb.org/"
},
"bugs": {
"url": "https://github.com/scottlamb/moonfire-nvr/issues"
},
Expand All @@ -16,6 +20,7 @@
"homepage": "https://github.com/scottlamb/moonfire-nvr",
"license": "GPL-3.0",
"name": "moonfire-nvr",
"description": "security camera network video recorder",
"repository": "scottlamb/moonfire-nvr",
"version": "0.1.0",
"devDependencies": {
Expand All @@ -28,6 +33,7 @@
"css-loader": "^3.4.2",
"eslint": "^7.0.0",
"eslint-config-google": "^0.14.0",
"favicons-webpack-plugin": "^3.0.1",
"file-loader": "^6.0.0",
"html-loader": "^1.1.0",
"html-webpack-plugin": "^4.3.0",
Expand Down
Loading

0 comments on commit 45abeb2

Please sign in to comment.