Question

I want to display a static HTML page with expressjs. What's the fastest way to do so? Currently I have a html file stored in the file system and I'm using res.sendfile(home + "/public/file.xml")

Is sendfile the fastest way to do it or might storing the file in some kind of database be faster?

Thanks

Était-ce utile?

La solution

Storing files in database? Well, some people try to do such evil things. But what is the point? I mean database engine has to read the file from disk as well. Additionally has to do many other things making the loading process longer.

Now you seem to confuse some things. Sending files is the same thing as sending any other response. At some point you have to send the binary data, so you cannot avoid using res.send (or any other form of it). This is of course if we are talking about Node.js, because you might consider serving files via nginx, which is probably the best static file server there is.

One last thing: if you still want to serve files via Node.JS, then you may consider caching them in memory. This of course depends on how many and how big files you want to serve. This is as easy as creating global variable which holds the data and sends it whenever there is a request. That's the only real performance boost you can make with Node.JS.

Autres conseils

Express has support for static file serving: app.use(express.static(__dirname + '/public'));.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top