After all the talk in the comments, I realized one thing: you can't delete folders in Heroku dynos! And you probably wouldn't want to anyways... Those folders look important (remember: Heroku dynos are usually mini-linux OSes, so that .apt
folder probably contains some of those mini-linux OS files). And of course, those .apt
and .heroku
folders probably don't add to your slug size. Sorry for that wild goose chase.
So? Let's reduce the sizes of stuff that actually matter.
Number one: reduce your node_modules
size.
Since your node_modules
folder is the biggest folder that you could control, let's start there. We'll be following this article. I'll be modifying some instructions so that they work with Heroku.
- Reduce the number of dependencies: This may sound like a no-brainer, but it helps a lot. Think about the packages you install. Do you really need them? And if you do, is there a more lightweight package somewhere out there that you could use instead? Example:
A lot of times I see people installing Jest just for simple unit tests (about 460+ dependencies, +/-60MB) when there are smaller libs that will do exactly the same (Mocha – 115 dependencies, 12MB).
2. Remove unnecessary files: Besides the usual installed when you install a package (.js
files, etc.), there's also a lot of... unneeded junk included (README
s, CHANGELOG
s, source files...). Because you can't remove those files manually (and who wants to), you need to use an automated tool and Heroku build scripts. Here's an example (remove the comments when you put this in your package.json
).
"scripts": {
// Other scripts...
// The following script dowloads node-prune (https://github.com/tj/node-prune)
// in the current build directory and runs it.
// The following script is run AFTER Heroku installs dependencies, but BEFORE
// Heroku caches them.
// EDIT: You have to do `./node-prune` instead of `node-prune`.
"heroku-postbuild": "curl -sf https://gobinaries.com/tj/node-prune | PREFIX=. sh&&./node-prune"
}
Annnd...
That's about all you could do. The other steps mentioned in that article won't help on Heroku. And as you already mentioned, your static files aren't really taking up much space–it's actually just node_modules
. I can't think of any other ways to reduce your slug size (unless you want to move your static files to an external storage facility and do some obscure get-and-cache maneuverers to serve them to clients...).
NOTE: I have not tried any of these steps. These should work in theory, but I'm not positive if they work or not.