Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 304 support to the file middleware #29

Open
creationix opened this issue Jun 2, 2012 · 3 comments
Open

Add 304 support to the file middleware #29

creationix opened this issue Jun 2, 2012 · 3 comments

Comments

@creationix
Copy link

While I don't believe a framework at this level should be sending Expires headers, there is no reason it can't implement 304 support using either Etags or LastModified headers (or maybe even both).

For etags, I would suggest something fast like https://github.com/c9/vfs/blob/master/local/localfs.js#L30-32 instead of hashing the content of the file or some other expensive operation.

@mjackson
Copy link
Owner

mjackson commented Jun 5, 2012

Yes, I agree with you here. Improved support for HTTP caching is something that I intend to add soon to strata, not just in the file middleware but in other places as well.

@creationix
Copy link
Author

304 isn't really caching. It's just a conditional request. I don't think putting caching at the framework level is a good idea since proper caching is so application logic specific.

Also, when I was working on connect, I too tried to handle caching and 304 as a standalone middleware, but in the end decided that was a bad approach. There is too much leaky abstraction and 304 can be handled much better inside the file middleware. It's already statting the file and already has the request headers. It only needs to check if the stat matched the conditional request and skip the body and send 304. This is very simple and easy to get right. It makes sites much faster even if they don't use any caching at all.

@mjackson
Copy link
Owner

mjackson commented Jun 5, 2012

Good point. I appreciate you sharing your previous experience, and I tend to agree that the file middleware should be handling this responsibility. I haven't looked into the spec for the Etag and Last-Modified headers lately, but I'll try and get some time to look into it and follow the implementation you suggest soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants