In the ExpressJS documentation there is nothing about how the files are loaded.
My question is: when I request a static file, is the file loaded form the disk with every request? Or it is somehow cached? If so, how?
Express will not automatically cache static content. For that we need to use https://www.npmjs.com/package/cache-control middleware. More info here (http://blog.modulus.io/nodejs-and-express-static-content) which helps
When I request a static file, is the file loaded form the disk with every request?
Most likely, it will not. All modern OS'es cache file data (or rather, disk blocks) in memory, so subsequent accesses to that data are read from memory instead of having to read it off disk again.
This obviously depends on how much free memory your system has, and if the memory is needed for other tasks, the disk data will (gradually) be purged from that cache (least-used data first, usually).
From Node, and therefore Express, you don't have much control over this mechanism, so from that standpoint it looks as if the file is read from disk for every request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With