# Caching Elm downloads on Netlify builds

**URL:** https://discourse.elm-lang.org/t/caching-elm-downloads-on-netlify-builds/5077
**Category:** Show and Tell
**Created:** [January 26, 2020, 7:52pm UTC](https://discourse.elm-lang.org/t/caching-elm-downloads-on-netlify-builds/5077 "2020-01-26T19:52:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dillonkearns](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dillonkearns/32/1587_2.png) [@dillonkearns](https://discourse.elm-lang.org/u/dillonkearns)
#### Post date: [January 26, 2020, 7:52pm UTC](https://discourse.elm-lang.org/t/caching-elm-downloads-on-netlify-builds/5077/1 "2020-01-26T19:52:43Z")

</div>

Hello all,

Evan requested that people take some time to make sure their Elm downloads are being cached on their CI environments. I came up with a solution for Netlify builds.

Here’s what the change looks like in your `netlify.toml` config:

```auto
[build]
  publish = "./dist/"
- command = "npm run build"
+ command = "export ELM_HOME=\"$NETLIFY_CACHE_DIR/elm\" && npm run build"

```

I updated the `elm-pages-starter` repo with that config for anybody who uses that template going forward:

> <https://github.com/dillonkearns/elm-pages-starter/commit/ee1a1ce4e55cef6299f0f74188f5d8a98807787f>

## The details

Here’s the before and after:

 ![Image 2020-01-26 at 11.39.40 AM](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/2X/b/b228d813d5d98fbac5e426259c7b7776991b1ccb.png)

It’s nice to shave off a few seconds (on average) from the build, and make it more resilient in case there is ever an outage.

I’m sure there could be a more elegant solution here for how to set the environment variable in Netlify. I played around with it for a while and had trouble getting it to work writing it with this alternative that I saw in [these docs](https://docs.netlify.com/configure-builds/file-based-configuration/#configuration-details):

```auto
[build.environment]
  # doesn't seem to work
  ELM_HOME = "$NETLIFY_CACHE_DIR/elm"

```

But that’s just a minor aesthetic issue. Otherwise, everything seems to be working smoothly!

Hope that’s helpful for others!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)
#### Post date: [February 5, 2020, 7:52pm UTC](https://discourse.elm-lang.org/t/caching-elm-downloads-on-netlify-builds/5077/2 "2020-02-05T19:52:48Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
