Skip to content

Commit 540cbd9

Browse files
ramhojNicklas Ramhöj
andauthored
Add troubleshooting section about CDN URL gotcha (#3164)
* Add troubleshooting section about CDN URL gotcha This PR adds a new section to the troubleshooting document explaining a gotcha where the javascript asset file can be incorrectly linked when `config.asset_host` is configured with different URLs in different environments and assets are not re-compiled between those environments. As the new section explains this is common on Heroku where the user is encouraged to use their pipeline promote feature that does not re-compile assets between apps. A common pattern is to use one app as a staging environment to evaluate builds. Upon acceptance, the staging app is “promoted” to the production environment. If `WEBPACKER_ASSET_HOST` is not set to an empty value in the staging application that application’s CDN URL will be compiled into the manifest.json file and reused in the production application. This issue can be tricky to detect as there might be no immediate error. The file probably still exists as it’s used by staging. When the staging environment later is re-deployed with new finger-printed assets the CDN will eventually remove the asset files that production is still dependent on. * Use more correct term "host" over "URL" Small update to the copy where the term URL was incorrectly used. Co-authored-by: Nicklas Ramhöj <[email protected]>
1 parent f1f4b7c commit 540cbd9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/troubleshooting.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,21 @@ module.exports = merge(webpackConfig, {
192192
],
193193
})
194194
```
195+
196+
## Wrong CDN src from javascript_pack_tag
197+
198+
If your deployment doesn't rebuild assets between environments (such as when
199+
using Heroku's Pipeline promote feature). You might find that your production
200+
application is using your staging `config.asset_host` host when using
201+
`javascript_pack_tag`.
202+
203+
This can be fixed by setting the environment variable `WEBPACKER_ASSET_HOST` to
204+
an empty string where your assets are compiled. On Heroku this is done under
205+
*Settings* -> *Config Vars*.
206+
207+
This way webpacker won't hard-code the CDN host into the manifest file used by
208+
`javascript_pack_tag`, but instead fetch the CDN host at runtime, resolving the
209+
issue.
210+
211+
See [this issue](https://github.com/rails/webpacker/issues/3005) for more
212+
details.

0 commit comments

Comments
 (0)