You need to add the following code in your application, after first render or whenever you want, to register the service worker:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js');
}
If supported this code will register the service worker.
If you want to add in index.html:
<script>
const baseUrl = document.querySelector('base').href;
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register(baseUrl + 'service-worker.js');
});
}
</script>