'javascript script src error 404 Not Found

I'm doing something with .net core. I have some jquery code that I use in almost every page and I want to set that specific code in one file and reuse it in others. That common code has function that shoudl be called from others files. Exactly I have some function for my modal pop up. But I'm getting this error in browser "Failed to load resource: the server responded with a status of 404 (Not Found)" My question is similar as on this link, but replies didnt help me How to add jQuery in JS file

My code in VS

@*<script src="~/js/Event/OverViewNew.js"></script>

When I put all code in one file this works*@

$(document).ready(function () {
    var script = document.createElement('script');
    script.src = "~/wwwroot/js/Event/OverViewNew.js";  //doesn't work 
    //script.src = "~/js/Event/OverViewNew.js"; doesnt work 
    script.type = 'text/javascript';
    document.head.appendChild(script);
    //document.getElementsByTagName('head')[0].appendChild(script);

    var script2 = document.createElement('script');
    script2.src = '~/wwwroot/js/Helper/Modal.js'; //doesn't work
    //script2.src = '~/js/Helper/Modal.js';  //doesn't work
    script2.type = 'text/javascript';
    document.head.appendChild(script2);
    //document.getElementsByTagName('head')[1].appendChild(script2);
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source