DEV Community

Mohit Bajoria
Mohit Bajoria

Posted on

Reducing heroku build time

If you have been facing issues with larger build time on heroku, probably your slug size is getting out of hand.

Here are some of ways you can reduce your slug size which can reduce build time

.slugignore

This is just like .gitignore we use for ignoring files in git. Add all the folders, files which are not necessary for your app to use such as

  • design files (.psd)
  • .pdf files
  • test data

Add this .slugignore to root of the repository

.pdf
.psd

cache node_modules

On heroku, set NODE_MODULES_CACHE=true and in your package.json add node_modules in your cacheDirectories

package.json

“devDependencies”: {...}“
”cacheDirectories”: [“node_modules”]

Move static assets to S3 or any storage provider

You should move all static files - image, video, pdf etc to S3 or any storage provider so that it doesn’t compile with your app.

Remove unused dependencies

Check for unused dependencies in your node project and remove it as it increases the installation time

You can use the below command to check for un-used dependencies and remove it manually

npx depcheck

Git repo clean up

Install the Heroku Repo plugin

heroku plugins:install heroku-repo

Then run:

heroku repo:gc --app your-app-name
heroku repo:purge_cache --app your-app-name

These commands will execute git gc --agressive (git-clean) and delete the contents of the Heroku build cache stored in your application’s Git repository.

Hope this helps!

Feel free to comment if you have any more suggestions 🤘

Oldest comments (0)