I'm new to MVC / .net and currently doing some simple exercises. I have this javascript code where I try to register my service-worker but for some reason, it's not running. I followed all the tutorial that I can find, searched up on this but still, it doesn't work. So I'm at lost here. Thank you for helping.
@RenderSection("pageScripts", required: false)
@section pageScripts{
<script type="text/javascript" language="javascript">
console.log('test script');
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').
then(function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
}
</script>
}
console.logdidn't even print that test string.@RenderSection("pageScripts", required: false)? I tried your code, with@RenderSection("pageScripts", required: false)in the file_Layout.cshtml, and the@sectioninIndex.chtml. Theconsole.logcall worked for me._Layout.cshtmlbefore the</body>tag