ForbesLindesay / browserify-middleware

express middleware for browserify, done right
http://browserify.org
MIT License
381 stars 66 forks source link

Overhead of the middleware compared with fs #31

Closed motiooon closed 10 years ago

motiooon commented 10 years ago

Hi,

I open this as an issue because I don't see any other means to ask my question. What is the overhead of browserifying on the go, as a middleware? I assume that accessing the browserifyed file via file system is faster than browserifiying and then serving the file. Do you have any benvhmarks in that regards? Please let me know, also if there is a better place to ask the question I'm happy to post my question there as well.

Thanks

ForbesLindesay commented 10 years ago

If you have the cache enabled (which it is by default in production) then it serves all but the first request from memory. It even pre-computes the gzipped version and the md5 for the etag so it should be much faster than most fs serving.

motiooon commented 10 years ago

You can use a caching middleware for files grabbed with fs and then keep them and serve them from memory.

I understand though that the browserify middleware comes with caching built in. So to make sure I understood corectly: first time it hits the route the midleware does all the processing(browserifying, caching, md5, gzip, etag etc..) and all subsequent are using the cached version.

So the overhead might be the one timer when the first user that hits the page. Is there any option to preprocess all assets on server start or the user has to request a file to trigger the process?

ForbesLindesay commented 10 years ago

True, although most caching middleware I've seen still re-computes the gzipped version for each request and performs fs.stat once for each request. For this module we assume that in production with caching enabled you aren't ever going to change the JavaScript files so we do no re-computation after the first request.

Yes, the first time someone requests the file, all the work is done from scratch. At the moment we don't have an option to preprocess all the assets. I would be happy to consider such a feature. For the versions that serve up a single file this should be fairly simple. The versions that serve up a folder probably shouldn't have this feature as some files in the folder may never be requested and thus would be needlessly cached into memory.