I would like to use a very strict Content Security Policy which does not allow inline Javascript. My views are rendered with php. All my Javascript Logic needed throughout the application is already external concatenated in one Javascript file app.js. Only the page specific initialization logic is inline in the php views, e.g.:
<script>
jQuery(document).ready(function(){
cebIntranet.home.init();
});
</script>
Now my question is how to also externalize the inline Javascript initialization logic. I could think of the following approaches but I am not happy with them. Is there a better solution? Which are the recommended best practices?
- Create a separate Javascript file for each page which does only hold the initialization logic => I do not like the idea to request an additional file which has at least only one line in it.
- Move the initialization logic also into the app.js file and make them dependent from the body id or class. => I do not like the idea to have a big if statement which chooses the right initialization logic dependent on a body class or id.