We are re-architecting some of our applications, and one of the requirements is to be able to adhere to content security policies that disallows inline scripts.
In general most of the event handlers and blocks of logic are already in external files, and moving the remaining stragglers isn't an issue, with the following exception.
We have settings that are stored in a SQL database, and we must make some of these values available to the .js files for the rendered HTML page.
Normally I'd do something like:
<script>
var ns.i = '<?= $i;?>',
ns.j = '<?= $j;?>';
</script>
Seems to me I have these potential options:
I have thus far been unable to locate recommendations or documented best practices for this type of thing.
refactoring this code is a lot of work and I want to do my best to ensure we're doing it the best way possible at this time.