serve icon indicating copy to clipboard operation
serve copied to clipboard

304s for unmodified files

Open kevin-roark opened this issue 10 years ago • 9 comments

it would be great if requests for unmodified files got a 304 status code, it would make serving static websites much faster :).

kevin-roark avatar May 05 '16 05:05 kevin-roark

I've tried to make it work in https://github.com/zeit/micro-list/commit/6bd503184a968f1cbbb5b43f2d326d34f3b9d55a (it should, but it sadly doesn't, I think). Will take another stab at it soon!

leo avatar May 31 '16 08:05 leo

nice! I may have spotted a bug (I'll comment on the commit) but I also could be wrong :)

kevin-roark avatar May 31 '16 16:05 kevin-roark

Sadly, that wasn't the problem. I've tried a few things, but nothing seems to work. The main problem is probably that the files (except the assets of micro-list itself) don't even get saved to the cache. Maybe @rauchg can take a stab at this?

All in all, the request doesn't contain the "if-modified-since" header (except when it's an asset, like I said).

leo avatar May 31 '16 16:05 leo

@leo you must supply an ETag first with every file, which could be a very quick hashing function (like crc32) concatenated file mtime

rauchg avatar May 31 '16 17:05 rauchg

Should be fixed in v0.5.0!

leo avatar Jun 23 '16 17:06 leo

Hey,

Just wondering if it's possible to get more infos on how caching really works.

Let's suppose I build my frontend at t1 and produce 2 files vendor.js and app.js, and serve them on now-serve. As I would use it as a CDN, I want caching to kick in. Now let's supposed I build frontend at t2 and produce the same 2 files that I redeploy with now-serve.

On second deploy, vendor.js is exactly the same as before (because my app libs did not change), but app.js is different (using hash compare is enought).

Will the headers be correctly set to enforce that the user see immediately the changes to app.js, and get a 304 for vendor.js ?

slorber avatar Oct 13 '16 22:10 slorber

@rauchg in my example, the vendor.js of the 2nd deployment has been rebuilt (so I guess it has different mtime), but content is exactly the same as before and I want a 304 instead of a cache miss. Is it possible with now-serve, or would it be possible to make it an option?

slorber avatar Oct 13 '16 22:10 slorber

according to my test it seems it's actually working like I want. The modified time of a file is not updated if the content is exactly the same as before as far as I see

Edit: no, not working

slorber avatar Oct 25 '16 13:10 slorber

Opened another issue because 304 does not work for me: https://github.com/zeit/list/issues/40

slorber avatar Oct 26 '16 13:10 slorber