D
Deno

help

Cache related headers not included in deno deploy for static file serving

Rrajsite2/18/2023
I have a hello world level static site using serveDir. When I run the site locally I see that Weak E-Tag headers are included in responses for the static files and can verify in dev tools that caching works. When I deploy the site with deno deploy I don't see any caching and each request sends the full response to the browser. I can see that compression is running as described in the caching documentation but the docs seem to suggest that if Weak E-tags are included (which I assume is the case since that is how serveDir is behaving locally) that I would expect them in the responses. - Any ideas on why deno deploy is not including caching headers in responses? - Related, how can I get insights into the responses of my app before Deno's frontend (i.e. how can debug / confirm my server is still including E-Tags in it's responses before the Deno deploy gateway takes over). Deno deploy caching docs: https://deno.com/deploy/docs/compression#what-happens-to-my-etag-header Example app:
import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
import { serveDir } from "https://deno.land/std@0.177.0/http/file_server.ts";

serve(async (req) => {
return await serveDir(req);
});
import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
import { serveDir } from "https://deno.land/std@0.177.0/http/file_server.ts";

serve(async (req) => {
return await serveDir(req);
});
In a directory structure like the following:
index.html
other_static_stuff/
src/main.ts
src/deno.json
index.html
other_static_stuff/
src/main.ts
src/deno.json
Deployed using deployctl with the current directory at the root of the path shown above and pointing to src/main.ts. Can see an example deployed site here showing caching not working: https://rajsite-gnpsdwjvtpk0.deno.dev/
ABTAndreu Botella (they/them)2/18/2023
I noticed this as well, but it's not related to Deploy stripping the headers it's because serveDir's handling of Last-Modified and ETag headers depends on the file's last modified timestamp and Deploy's filesystem is virtual and seems to not provide those
ABTAndreu Botella (they/them)2/18/2023
GitHub
Support querying modification timestamps (mtime) for the Deploy f...
I recently noticed that std/http/file_server.ts in Deploy doesn't add Last-Modified or ETag headers, which results in clients having to redownload the files when they might already have the...
ABTAndreu Botella (they/them)2/18/2023
ayame113 then made a PR to change serveDir to use Deploy's deployment ID envvar if it's present so that should probably work on the next release of std although the last modified timestamp will always be that of the last deployment, but that's better than not having it
Rrajsite2/18/2023
Have any approaches on how you figured that out? Logging responses yourself and noticing expected headers weren't present or is there some way to observe that in the deno deploy tooling? Or just source inspection and clever thinking 😛
ABTAndreu Botella (they/them)2/18/2023
I noticed that the ETag header weren't present on Deploy but were when running the server locally, and then I searched for "ETag" on the source 😅
Rrajsite2/18/2023
Diving into the source to see what's happening is a lot more approachable in Deno, it's pretty nice. Feels like the deno deploy observability tools have room to grow. But still learning and all very cool!
ABTAndreu Botella (they/them)2/18/2023
yeah! to be fair, I already knew that Deploy uses a virtual filesystem, so seeing that those headers were present only when mtime was set made things pretty clear I don't know the details of the virtual filesystem, but I'm quite confident that they use a different implementation of the filesystem lookup than Deno does
Rrajsite2/18/2023
Looking at the PR made me wonder how much of the deno std library had Deno Deploy specific logic in it. Does seem like there is some just searching for deploy but not a huge amount. Hopefully that's something they'll want to avoid growing too much 😅 Thanks for the help @Andreu Botella (he/they) 🙂 Have a good one!
ABTAndreu Botella (they/them)2/18/2023
sure!

Looking for more? Join the community!

Recommended Posts
Error with relativ import path after "deno install"Is it possible that imports in deno.json are ignored after "deno install"? ```bash deno run ./my-Run examples on WindowsAnyone know how to run the `Piping to files` example on Windows? https://deno.land/manual@v1.30.3/exPython alternative to ctypes, can't figure how to convert a codeHello, I am trying to convert a Python ctypes code to Deno using FFI, but can't know why its not woSuggestions for minimal JSX rendering?Any suggestions for rendering jsx to a string (or ideally a stream), in the most minimal manner fromDeno.run Strange IssueI use `Deno.run` + stdout/signals/etc a lot, but this behavior is beyond my current debugging abilitProperly continuously read data from a ReaderWhat's the proper way to continuously read from a `Deno.Reader`? I'm trying to parse incoming HTTP2npm:redis – everything returns `string`?Every command I try to use from `npm:redis` seems to have inferred return type `string`. Look at theMy magic middlewares typeIf anyone wants a typescript challange here is one: I am trying to create a tuple type which containRead one byte at a time from ReadableStreamWhat would be the most obvious way to read a single byte from a ReadableStream at a time?My deno.lock file exceeds 4000 lines of JSON nowIs this common for application projects? Is there any nice way to clean it up?importing packages breaks typesIm importing `Receiver` from https://deno.land/x/upstash_qstash@v0.3.2. but as soon as i import thisBug report: deno.land website returns a 500 error for JS filesOn https://deno.land, I noticed that the Node vs Deno comparison didn't seem to do anything. From Deno stopps at file.read()I am currently working on a way to communicate with a COM device. I can successfully open and read f[Resolved][Fresh] How to load data asynchronously after rendering a page ?Hi ! I was wondering if someone could help me understand the paradigm to load data asynchronously afSupabase Auth UI in FreshI'm building a simple web. I'd like to use Supabase's Auth UI, namely the `Auth` component, for handAny tool that will complie my TS code to JS?I have coded a website in typescript using Deno, but I want to convert it to JS code. I know the DenHow to get remote IP address when using Deno.serve?I'm using connInfo when using Deno from STD but the native http server doesn't seem to have such intTwo questions on documentationRTFM in 3... 2... 🙂 Question 1: How do i hide documentation for specific exports, i do not want Is there any simple way to keep track of the heap/stack usage of a running Deno application?I have made a Deno application and I'm curious to know if there's heap/stack issues that I should fiusing data from one deno bench in anotheris there any good way to re-use the results generated in one deno bench in another one? example: `