I have a page that switches content using fetch API. Every content is accompanied with a js file. Some of them are type='module'. However although modules are working excellent during the first load, when I switch content (call a different fetch endpoint) and switch back again the corresponding script doesn't seem to work. When the whole page is changed (e.g. go to profile page and then again to main page) the scripts are working normally.
--- inside the main page the part that calls the content ---
...
auth.fetch(partUri).then((resp) => {
return resp.text().then(text => {
$('.title > h2').text(titles[ch - 1]);
$('#part-' + partNo).html(text);
}
});
});
...
--- Inside the content's html file ---
...
<script> <--- this script is working after switching back
new SimpleLightbox('.gallery-item a', {
disableScroll: false
});
</script>
<script type="module" src="js/part-3.js"></script> <--- this script is working only the first time