DEV Community

Cover image for Your Heroku App Is Slow to Load Because Of This.
Elijah Trillionz
Elijah Trillionz

Posted on

Your Heroku App Is Slow to Load Because Of This.

No doubt that Heroku is a great tool for developers. One particular reason for me is its generosity. I will explain how

Heroku Dynos

If you're already using Heroku, then you should be familiar with dynos. A dyno is a lightweight, isolated, Linux container. It is basically how Heroku runs your app.

With a free plan, you can get 550 hours of dyno per month with an unverified account and 1000 hours of dyno with a verified account. (Your account gets verified when you submit your card details. See more details here.)

What this means is, for each month, your app can only run for 1000 hours (verified account) or 550 hours (unverified account).

To preserve your dyno hours from burning out or wasting, Heroku puts your app to sleep after 30 minutes of inactivity. How generous!

This is what makes your app is slow to load. When your app's dyno is asleep, waking it up may take some time. But after the first load, it starts loading pretty fast because the dyno is active.

How do we solve this?

If you don't want your app to go to sleep no matter the inactivity, then I have solutions for you. There are 744 hours in 31 days, so having a verified account keeps you ahead.

Before we look at the solutions, let's see why you may need your app to always be on:

Let's say you have a portfolio, as a full-stack, you wouldn't want a potential client to wait that long for your dyno to wake up.

The worst part is when you're using a custom domain and not a Heroku subdomain (yourapp.herokuapp.com). With the subdomain, He/She may consider knowing fully well your dyno is waking up. But with a custom domain ... you will have to explain yourself then.

Another scenario for you to keep your app alive is with Discord Bot or Twitter Bot. You'd want these bots to always be active at any time right?

What you need is someone to keep your app active so your dyno won't go to bed. You need someone to always reload your app every 5 minutes or 10 or 20 but not 30 above.

That someone is Uptime robot. Uptime robot will keep your app active and also looks out for downtime (when your app stops working). I will show you how to monitor and keep your app active with Uptime robot.

Visit www.uptimerobot.com. Register an account. You will be redirected to your dashboard.

  1. Click the + Monitor button
  2. In the monitor type field select HTTP(s)
  3. Fill the other fields with a name for your app, the URL of the app.
  4. Set an interval, the minimum is 5 minutes.
  5. Select the contact you would want them to notify for any downtime. It's optional.
  6. Lastly click the green Create Monitor button.

Soon as you are redirected to your dashboard, you will see that app you're monitoring in your dashboard. Click on the name of the app to see more stats of the app.

Another option is to upgrade your Heroku plan from a free tier to a paid plan, here is Heroku pricing.

Summary

I almost wanted to switch from Heroku because of this issue. I used mine for an API and a discord bot. But this solution solved my problem.

I have a Discord server for web developers to help with their coding journeys. See Info here.

If you like this post and want to support me you can buy me a Coffee.
Thank you for reading.


You might be interested in

  1. Tools To Improve as a Programmer
  2. How I made a NoSQL Database clone with JavaScript Classes

Top comments (12)

Collapse
 
danidiaztech profile image
Daniel Diaz

I found really useful your article, so thanks for sharing it!
But from a couple of years until now, heroku had set protection against these tools, so now the platform has certain restrictions.
An example is that a free heroku app must sleep at least a hour a day, if it passes the restriction, you'll be charged.

Collapse
 
elijahtrillionz profile image
Elijah Trillionz

Oh wow.
I didn't know about this. I will look into this. Thanks

Collapse
 
bairrada97 profile image
bairrada97

if app is asleep and 10 users enter at same time will be slow for only 1 user or for 10 users?
Also if you usually have an app with 1k visitors is it really that bad that only 1 will get slow load?
But really nice solutions and I might apply to my projects

Collapse
 
elijahtrillionz profile image
Elijah Trillionz

Good question @bairrada97 . If the app is asleep it will only be slow to load for the first person to wake the app.
So if I am the first person to load the app, then it will only be slow for me, if after 5 minutes someone else tries to load the app, it will not be slow.

For the second question:
Yeah it's not that bad for just one person (that's why I consider Heroku generous). But why does my app need to sleep anyway if I have more than enough hours per month

Collapse
 
quangpl profile image
Quang Phan

I'd like to refer npmjs.com/package/awake-heroku that is useful for heroku

Collapse
 
elijahtrillionz profile image
Elijah Trillionz

That's a good resource. Have you tried it before?

Collapse
 
nguyentran6698 profile image
nguyentran6698

Thank you so much for sharing.

Collapse
 
elijahtrillionz profile image
Elijah Trillionz

Glad you found it useful

Collapse
 
safventure11000 profile image
Saf11000

It works! Thanks for sharing.

Collapse
 
elijahtrillionz profile image
Elijah Trillionz

Enjoy!

Collapse
 
cdthomp1 profile image
Cameron Thompson

Insightful!

Collapse
 
yongchanghe profile image
Yongchang He

Interesting! Thank you for sharing this!