Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #430 from zarathustra323/add-init-only
Browse files Browse the repository at this point in the history
Add support for `initOnly` in deferred script loading
  • Loading branch information
brandonbk authored Sep 22, 2022
2 parents 0cece40 + 2eec1e8 commit bf1793e
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script>deferScript('load', { name: '${input.name}' });</script>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$ const src = input.src || "https://cdn.parameter1.com/deferred-script-loader/60731937.js";
$ const src = input.src || "https://cdn.parameter1.com/deferred-script-loader/6210e032.js";

<script>(function (s,o,g,a,m) { a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.defer = 1; a.src = g; m.parentNode.insertBefore(a, m); })(document, 'script', '${src}');</script>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
"required": true
}
},
"<marko-web-deferred-script-loader-load-script>": {
"template": "./load-script.marko",
"@name": {
"type": "string",
"required": true
}
},
"<marko-web-deferred-script-loader-register>": {
"template": "./register.marko",
"@name": {
Expand All @@ -31,6 +38,7 @@
"@target-tag": "string",
"@request-frame": "boolean",
"@init": "string",
"@init-only": "boolean",
"@on-script-build": "string",
"@on-script-load": "string",
"@attrs": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ $ const {
});

$ const init = `function() { ${input.init || ''} }`;
$ const initOnly = defaultValue(input.initOnly, false);
$ const onScriptBuild = `function(script) { ${input.onScriptBuild || ''} }`;
$ const onScriptLoad = `function() { ${input.onScriptLoad || ''} }`;
$ const attrs = JSON.stringify(getAsObject(input, "attrs"));

<script>deferScript('register', { name: '${input.name}', src: '${input.src}', on: '${on}', requestFrame: ${requestFrame}, targetTag: '${targetTag}', init: ${init}, onScriptBuild: ${onScriptBuild}, onScriptLoad: ${onScriptLoad}, attrs: ${attrs} });</script>
<script>deferScript('register', { name: '${input.name}', src: '${input.src}', on: '${on}', requestFrame: ${requestFrame}, targetTag: '${targetTag}', init: ${init}, initOnly: ${initOnly}, onScriptBuild: ${onScriptBuild}, onScriptLoad: ${onScriptLoad}, attrs: ${attrs} });</script>
1 change: 1 addition & 0 deletions packages/marko-web-gam/components/init.marko
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $ const { on } = input;
request-frame=input.requestFrame
target-tag=input.targetTag
init="window.googletag = window.googletag || {}; window.googletag.cmd = window.googletag.cmd || [];"
init-only=input.initOnly
/>
</if>
<else>
Expand Down
3 changes: 2 additions & 1 deletion packages/marko-web-gam/components/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"@src": "string",
"@on": "string",
"@target-tag": "string",
"@request-frame": "boolean"
"@request-frame": "boolean",
"@init-only": "boolean"
},
"<marko-web-gam-head>": {
"template": "./head.marko",
Expand Down
1 change: 1 addition & 0 deletions packages/marko-web-gtm/components/init.marko
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $ const start = input.start == null ? false : input.start;
request-frame=input.requestFrame
target-tag=input.targetTag
init=`var w = window, l = '${name}'; w[l] = w[l] || [];`
init-only=input.initOnly
/>
</for>
</if>
Expand Down
3 changes: 2 additions & 1 deletion packages/marko-web-gtm/components/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"@on": "string",
"@target-tag": "string",
"@request-frame": "boolean"
"@request-frame": "boolean",
"@init-only": "boolean"
},
"<marko-web-gtm-start>": {
"template": "./start.marko",
Expand Down
1 change: 1 addition & 0 deletions packages/marko-web-native-x/components/init.marko
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $ const src = "https://cdn.parameter1.com/native-x/1.0.0-rc.4.3.js";
request-frame=input.requestFrame
target-tag=input.targetTag
init="var i = window, r = 'fortnight'; i['FortnightObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments); };"
init-only=input.initOnly
/>
</if>
<else>
Expand Down
3 changes: 2 additions & 1 deletion packages/marko-web-native-x/components/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"@enabled": "boolean",
"@on": "string",
"@target-tag": "string",
"@request-frame": "boolean"
"@request-frame": "boolean",
"@init-only": "boolean"
},
"<marko-web-native-x-retrieve>": {
"template": "./retrieve.marko",
Expand Down
1 change: 1 addition & 0 deletions packages/marko-web-omeda/components/olytics/init.marko
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $ const clean = (js) => js.split('\n').map((line) => line.trim()).join(' ');
on=input.on
request-frame=input.requestFrame
target-tag=input.targetTag
init-only=input.initOnly
init=clean(`
window.olytics || (window.olytics = []), window.olytics.methods = ['fire', 'confirm'], window.olytics.factory = function(i) {
return function() {
Expand Down
3 changes: 2 additions & 1 deletion packages/marko-web-omeda/components/olytics/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"@on": "string",
"@target-tag": "string",
"@request-frame": "boolean"
"@request-frame": "boolean",
"@init-only": "boolean"
}
}
1 change: 1 addition & 0 deletions packages/marko-web-p1-events/components/init.marko
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $ const identityQueryBuilder = `identityQueryBuilder: function(query, cookies) {
request-frame=input.requestFrame
target-tag=input.targetTag
init="var i = window, r = 'p1events'; i['__p1e'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments); };"
init-only=input.initOnly
/>
</if>
<else>
Expand Down
3 changes: 2 additions & 1 deletion packages/marko-web-p1-events/components/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"@identity-query-builder": "string",
"@on": "string",
"@target-tag": "string",
"@request-frame": "boolean"
"@request-frame": "boolean",
"@init-only": "boolean"
},
"<marko-web-p1-events-track-content>": {
"template": "./track-content.marko",
Expand Down

0 comments on commit bf1793e

Please sign in to comment.