Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js + Express.js very slow serving static files

Sometimes when developing my current node project I will get a hanging refresh. Where the page will never load. I check the network tab in Chrome and see that its always hung up on a static files. The static file that gets stuck will differ, sometimes it will be a CSS file other times an image file.

I have tried to optimize all my files in hopes to resolve this issue but nothing has fixed it. If I hit refresh during a long load it will load the page correctly on the 2nd request. This does not happen every time I try to load the page but very often when switching between pages.

If I disable cache under the chrome network inspector, It will almost always happen.

**This is my 1st major node project so I could have made mistakes along the way. **

Entire project is hosted on github: http://github.com/polonel/trudesk

Example Load times: (Open image in new tab to see full-size)

like image 402
Chris Avatar asked Sep 29 '14 18:09

Chris


1 Answers

I had exactly the same issue. I just moved to a place with a pretty bad internet connection. Loading time of static files in my node.js app increased to more then 40s per file.

I just moved the static middleware

app.use(express.static(__dirname + '/public'));

to the top of app.configure function, before all the other app.* calls.

It's now working significantly faster.

like image 172
pzagor2 Avatar answered Oct 05 '22 02:10

pzagor2