This is my first heroku app... and I see that my heroku slug size is 296MB... getting uncomfortably close to the fast 300MB boot time.
This is a puppeteer app with ejs, path, and express installed. I have a bunch of static files but they don't seem to be taking up majority of the space..
I would really appreciate help with this!

Edit: My package.json looks like this now (don't see how I could really trim down my node_modules - in fact, I wanted to add more dependencies as I further develop my app):
"scripts": {
"start": "node server.js",
"heroku-postbuild": "curl -sf https://gobinaries.com/tj/node-prune | PREFIX=. sh&&./node-prune"
},
"dependencies": {
"ejs": "^3.1.5",
"express": "^4.17.1",
"path": "^0.12.7",
"puppeteer": "^5.3.1"
}
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.
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.
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 (
.jsfiles, etc.), there's also a lot of... unneeded junk included (READMEs,CHANGELOGs, 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 yourpackage.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"
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With