3 ms·
> serving static files has never been a problem I address this in the post; there's no problem with it, but it requires that you (or your end users) come up wi
by kevinburke 10y ago
> serving static files has never been a problem
I address this in the post; there's no problem with it, but it requires that you (or your end users) come up with a solution for deploying static assets to production, figuring out the relative paths between the working directory and the asset directory, and ensuring that the right version of the binary loads the right version of the assets. An example of the type of difficulty here is that you couldn't remember how to do it off the top of your head.
If you compile them into the binary, you (or your users) don't have these problems.
- beat 10y agoI thought compiling them into the binary was a very clever idea!
- AYBABTME 10y agoI've always assumed that compiling assets into the binary meant the http.FileServer can't use sendfile. I guess this means lower performance at scale, but I've never verified if this actually happened or its effect.
- vfaronov 10y agoLooking at Linux’s sendfile [1], it should be possible to use it like that in principle (but not with the standard http.FileServer, I guess). [1] http://man7.org/linux/man-pages/man2/sendfile.2.html http://man7.org/linux/man-pages/man2/sendfile.2.html
- jorams 10y agoWhen you serve files over https (which you always should) you can't use sendfile anyway. The data will have to be encrypted, so you can't have the kernel send the data straight into the socket.
- blaenk 10y agoI hadn't considered this before but it seems to make sense. If I have nginx configured with ssl and sendfile (X-Accel-Redirect) and my app sends an X-Accel-Redirect response to nginx, you're saying that it's not actually using sendfile under the hood?
- inimino 10y agoSendfile is just a kernel feature for directly sending a file to a socket. If you are doing literally anything other than just sending the raw bytes of the file over the network, it can't be used.
- blaenk 10y agoYeah I'm aware that it's a system call that only knows about file descriptors. It's just that it just now hit me that a consequence of that is that a web server configured to use ssl _and_ sendfile isn't really using sendfile, short of some hairy hack of writing/encrypting the response into a file (maybe in-memory with something like memfd_create) and using sendfile on that, which would defeat the purpose of avoiding user-space entirely.
- weberc2 10y agoAh, I misread. Thanks for clarifying.