breezewish / express-minify

Automatically minify and cache your javascript and css files.
https://npmjs.org/package/express-minify
MIT License
86 stars 18 forks source link

Question about file cache option #56

Closed aaazureee closed 6 years ago

aaazureee commented 6 years ago

Not actually an issue but I want to ask about the cache directory option. What's the purpose of storing files in the cache folder on the server? As far as i know, express static files support ETag, so what's the difference here? Your package is working fine for me by the way.

Martii commented 6 years ago

@aaazureee

What's the purpose of storing files in the cache folder on the server?

If the compression options are enabled, like uglifyjs, it doesn't need to compress them again which slows down server CPU since that particular package is CPU intensive the first round (try compressing Ace editor the first time and you'll see it takes about 5 times longer the first time and then it's almost instantaneous the next retrieval from any session) then your ETag can be served almost immediately from your production server. This is how our production works. Think of it as a store of parsed objects that really only need to be parsed once. You can skip when needed of course.

aaazureee commented 6 years ago

Thank you for the response. So it's like server side caching that cache the minified files.

Martii commented 6 years ago

So it's like server side caching that cache the minified files.

Yes and there is also dynamically generated CSS support (usually that also only needs to be done once) and few other things that I haven't dug into yet. Always out of time. :) Those can be cached or skipped too.

Glad it makes sense for you now. Took me a bit to understand its really useful purpose.