Using the Vite / Rollup bundler with a Vue app as an example, we can see how this issue applies to any modern web stack.
Vite automatically adds a hash to each js chunk, asset, and main.js file to indicate when changes have been made. However, there is an issue where if the hash of the main.js file changes, the website fails to load the Vue router and gets stuck on a blank index.html page until manually refreshed. One potential solution could be adding an error handler directly in the HTML file like:
<script type="module" src="/src/main.hash1.js" onerror="onMainScriptLoadingError"></script>
And inside the onMainScriptLoadingError
function, include:
window.location.reload();
This would allow for the page to refresh and download the new index.html with the updated main.hash2.js file without causing an infinite loop of refreshing. However, it seems strange that this approach is not mentioned in the official documentation of any bundler. Is there a better way to handle this issue without cluttering the server with multiple historic files or tying builds together?