Hey!
I’m running liveview in production and it’s great. I’m deploying using docker / releases and mix phx.digest.
Everything works perfectly 99% of the time.
However sometimes the css and js files are not loading properly. Someone will access the site one day, I’ll deploy, then the next day it looks like the stylesheet isn’t loading at all or certain buttons can’t be clicked.
Of course when the user clears their cache it works again… but they often don’t know how.
Phoenix has this on static changed solution… but window.reload doesn’t seem to remove memory cache of static assets so I wrote this:
<%= if @static_changed? do %>
<div id="reload-static" style="width: 100%; height: 80vh; display: flex; justify-content: center; align-items: center;">
<p>The app has been updated. <a href="#" onclick="window.location.reload(true)" style="text-decoration:underline;">Click here to reload</a>.</p>
</div>
<script>
const js = document.getElementById('main-js')
const css = document.getElementById('main-css')
fetch(js.src, {cache: "reload"})
fetch(css.href, {cache: "reload"})
</script>
<% end %>
I do inline styles because the stylesheet styles are not there.
Then I’m refetching the css and js static assets and then asking the user to click reload.
Do you think this is an effective solution?
I’m also half wondering if I’m messing something up with docker builds and static assets but I’m not sure.
Thanks!