Check out example codes for "service worker symfony webpack encore". It will help you in understanding the concepts better.

Code Example 1

<script>
var swPath = "{{ encore_entry_js_files('sw') | first }}";
</script>

Learn ReactJs, React Native from akashmittal.com