DEV Community

Mohit Bajoria
Mohit Bajoria

Posted on

4 3

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 🤘

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay