简体   繁体   中英

Node.js + Express server specific static files extremely slow

I have this very weird problem. I'm running an Express (Node.js) server with a React front-end. Ever since I've began developing it, it has run cleanly and without issues, taking a few seconds to load every refresh.

Today it started loading horribly - From 20 seconds to a full minute for a 2MB app.

I checked and found that there are two files - vendor.bundle.js and bundle.js (Created by gulp and contain the app code and external dependencies) that take much more time to load than others. Each of them weighs about 700KB and takes about 10 seconds to load. As a comparison, vendor.js weighs about 400KB and takes 1 second to load.

If that's not enough - I tried running the boilerplate for the app I'm using (It's an app from a tutorial so it weighs about the same) and it takes about 6 seconds to load.

I have absolutely no idea why is this happening or why is there a difference with these specific files.

Do you have any ideas? I've become quite desperate.

Thanks for any help.

Express static file serving and a bit of the sorrounding:

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

//Static files being served
app.use(express.static(path.join(__dirname, 'public')));

app.use(require('./routes/user-routes'));

app.all('/api/*', jwt_middleware({ secret: config.secret }).unless({path: ['/login']}));
app.use(function (err, req, res, next) {
  if (err.name === 'UnauthorizedError') {
    res.status(401).send('invalid token...');
  }
});

app.get('*', function (request, response, next){
  response.sendFile(path.join(__dirname, 'public', 'index.html'))
});

自行离开,如果它回来,将尝试调试模块。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM