With the Content Security Policy header set on a web server (https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), any inline script is blocked by modern browsers. It is recommended to place all javascript in .js files and configure the policy to authorize the domain where these .js files are hosted.
Fine, but my question is how are we suppose to pass data from the server-side application to the client script ?
For example if I want to call a js function which take server-side value as input, I still have to call the function like the code below (MVC.Net Razor View) in the page body which is blocked.
<body>
...
<input type="button" value="Test" onclick="DoSomething('@ViewData["SomeValue"]');" />
...
</body>
I found some way to pass data in the script src attribute querystring (http://feather.elektrum.org/book/src.html), but i'm not sure it is the best solution. I'm particulary worried about the caching issue of variables in src querystring. Is there a better way to do that ?