You could consider using https://developer.mozilla.org/en-US/docs/Glossary/IIFE#avoid_polluting_the_global_namespace Your shared JS would be an IIFE that you call with a config object like <script> initializeMapLogic({ bgLayerName : '@Model.DefaultBackgroundLayer', infoLayerName : '@Model.DefaultInformationLayer', onlyEnablePolygon : true, allowMultiplePolygons : true }); </script>