I am trying to improve a progressive web app that I made fairly recently. To save a little time when developing and to reduce the risk of an error I would like to display the version number automatically instead of manually copying it into HTML.
The version number is defined as the cache name in the service worker:
const cacheName = '1.6.2';
The service worker is registered by register.js which is called in the head of each HTML page.
<script src="register.js" defer></script>
Then in a script at the end of the body I have:
document.getElementById('versionNo').innerHTML = cacheName;
And in the HTML:
<span id="version">Version: <span id="versionNo"></span></span>
However this leaves the version number blank and the javascript console reports “jquery.js:2 Uncaught ReferenceError: cacheName is not defined”. Is there an error in my thinking or is this just not possible?