Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow page load in production #3767

Closed
Dzale opened this issue Feb 12, 2018 · 10 comments
Closed

Slow page load in production #3767

Dzale opened this issue Feb 12, 2018 · 10 comments

Comments

@Dzale
Copy link

Dzale commented Feb 12, 2018

Hey guys,

I have a simple app built with next.js and react. Average initial time of loading pages in production is between 4-6s, which is like crazy, since loading data from external API takes about 200ms.

Below is example of page load that doesn't even make request to external API:

DONE Compiled successfully in 6043ms12:51:07 AM

I have basic droplet on VPN (5$ / month) and i used PM2 to serve this app.

Any ideas how to improve this ? Will using "now" speed it up ? Or buying better/faster droplet ?

As i said it is very basic app (i don't have hundreds of packages, no additional webpack config, nothing), so no really space for improvement there. But having this high loading time is unacceptable!

@khuezy
Copy link
Contributor

khuezy commented Feb 12, 2018

There shouldn't be any compiling in production mode.
It looks like you're running: npm run dev

To run production:
npm run build
npm start

@Dzale
Copy link
Author

Dzale commented Feb 12, 2018

No, npm start doesn't support SSR (Server Side Rendering).

I am running following commands:
npm run build
pm2 start server.js

@khuezy
Copy link
Contributor

khuezy commented Feb 12, 2018

? npm start renders SS for me.

@Dzale
Copy link
Author

Dzale commented Feb 12, 2018

For me it throws 404 for each page that has to prefetch some data from API.

image

image

@khuezy
Copy link
Contributor

khuezy commented Feb 12, 2018

Can you post the script object in your package.json?

My npm start => node index

There's an open issue w/ slow compile time in dev mode: #3735
But I'm not seeing any slow downs running the build

@Dzale
Copy link
Author

Dzale commented Feb 12, 2018

My npm start => next start :D

@khuezy
Copy link
Contributor

khuezy commented Feb 12, 2018

Can you try: node index or whatever your main server app is?

@Dzale
Copy link
Author

Dzale commented Feb 12, 2018

I tried, the loading time is the same, about 6s. It's basically the same thing that pm2 start server.js does, pm2 just makes that command permanent.

Not sure what can be the problem. Maybe i should get better droplet...

However, thanks for the help.

@timneutkens
Copy link
Member

You are starting the app in development mode. Which is not optimized for production usage. In case you're using a custom server you need to set dev to false. In the examples we do it using process.env.NODE_ENV === 'production' So when starting your app you need to set NODE_ENV=production node server.js

@Dzale
Copy link
Author

Dzale commented Feb 12, 2018

works perfectly, thanks!

@lock lock bot locked as resolved and limited conversation to collaborators Feb 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants