I typically serve static files directly using:
app.use( express.static(__dirname+'/public') );
middleware. Your static files would be stored in
/<app-path>/public
This will allow you to access /<app-path>/public/some.html
at:
http://yoursite.com/some.html
If you put file.html
in /<app-path>/public/html/
, the following would resolve:
http://yoursite.com/html/file.html
http://yoursite.com/public/html/file.html
If the desired result is to have clean urls without extensions, then my suggestion will not do. However, if you don't mind file extensions within urls, the static middleware should reduce request times, maybe even dramatically. Also, maybe a templating engine like dust
or jade
may help? It would allow you to use the res.render
fn.
The thing is, I have seen request times increase when using:
res.sendfile(somepath +'/some.html');
Because express will pass that through its regex path resolution middleware before serving the file. If you have a ton of routes, that may also be slowing down request times.
Hope that helps!