سؤال

I want to precompile some Jade templates mostly based on server configuration (so result is static html) upon server startup. Then for every client request I want to serve this content as fast as possible.

There is probably several options, but I am not sure what would most efficient.

  1. Save in files and stream on every request
  2. Save in Redis database and stream (not sure how yet) on every request
  3. Store everything in memory as strings and send on every request

There is maybe more options I don't know about. I was even thinking about creating stream, that can be reused all over again for every request, but it doesn't seems to be possible.

I am not looking for ultimate super solution here, just maybe if you can share your experience on this topic.

هل كانت مفيدة؟

المحلول

You should put nginx in front of node.js. Then nginx can serve semi-static pages all by itself with high efficiency, and it can forward dynamic page requests to node.js. For more details on how to set that up, see: Node.js + Nginx - What now?

نصائح أخرى

Just adding to answer by John Zwinck You can use memcache additionally if you think for some reason setting static files (servable by nginx) wont work for you,or if the data is timed/needs to be updated frequently/needs to expire after some time-interval. Nginx has inbuild memcache module. you can have it query from memcache for specific urls.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top