Newer Version Available
Integrate Third-Party Libraries Using the Privileged Script Tag
Use the custom <x-oasis-script> tag in place of the standard <script> in the head markup or inline. Scripts loaded within this custom tag run inside a special iframe that’s exempt from shadow DOM and are always executed asynchronously.
<x-oasis-script> uses the same syntax as the <script> tag.
1<x-oasis-script src="third_party_library.js"></x-oasis-script>You can also use the tag to add event listeners and to import and export global variables with the imported-global-names and exported-global-names attributes. If you have custom code within the <x-oasis-script> tag, add the attribute hidden="true" to the tag. This attribute ensures that the custom code within the tag remains hidden from site visitors while the page is loading.
1<script>
2 window.testVar = "myTestVar";
3</script>
4
5<x-oasis-script hidden="true" imported-global-names="testVar">
6 // Custom code to access testVar
7 console.log(window.testVar)
8</x-oasis-script>1<x-oasis-script hidden="true" exported-global-names="testVar">
2 window.testVar = "myTestVar";
3</x-oasis-script>
4
5<script>
6 // setTimeout is needed in case this script tag is run before oasis script
7 setTimeout(function(){
8 // Custom code to access testVar
9 console.log(window.testVar)
10 }, 5000);
11</script>