سؤال

I'm using NodeJs with Express. I have a public directory containing many things essential for the client such as pictures.

When someone logs into my server, do everything contained in my express public directory transfered to the client? Or does it happen only once, on first log in, then after only what has changed is transfered?

I have many, many pictures in the public directory and I'm having bandwidth issues at the moment. Any solution?

Thanks.

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

المحلول

The only files that will be sent to the client are those requested specifically (unless you are using a manifest file). These files will be resent each time they are requested. There are ways to keep files from being resent unnecessarily, namely by using cache control. The Express framework allows you to do this fairly easily by setting the Cache-Control header. For example:

var oneDay = 86400000;
app.use(express.static(__dirname + '/public', { maxAge: oneDay }));

You may also want to consider compressing the output.

app.use(express.compress());

Both of these examples come from this blog post: http://blog.modulus.io/nodejs-and-express-static-content

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