Skip to content

Commit ad12327

Browse files
committed
scripts lazy load - improved app load speed
1 parent fdd18d4 commit ad12327

File tree

4 files changed

+45
-30
lines changed

4 files changed

+45
-30
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"last 1 firefox version",
4747
"last 1 safari version"
4848
]
49-
}
49+
},
50+
"devDependencies": {}
5051
}

public/index.html

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,5 @@
2424

2525
gtag('config', 'UA-153205738-3');
2626
</script>
27-
28-
<!-- Start of Async Drift Code -->
29-
<script>
30-
"use strict";
31-
32-
!function () {
33-
var t = window.driftt = window.drift = window.driftt || [];
34-
if (!t.init) {
35-
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
36-
t.invoked = !0, t.methods = ["identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on"],
37-
t.factory = function (e) {
38-
return function () {
39-
var n = Array.prototype.slice.call(arguments);
40-
return n.unshift(e), t.push(n), t;
41-
};
42-
}, t.methods.forEach(function (e) {
43-
t[e] = t.factory(e);
44-
}), t.load = function (t) {
45-
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
46-
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
47-
var i = document.getElementsByTagName("script")[0];
48-
i.parentNode.insertBefore(o, i);
49-
};
50-
}
51-
}();
52-
drift.SNIPPET_VERSION = '0.3.1';
53-
drift.load('kmcg4ky4chmh');
54-
</script>
55-
<!-- End of Async Drift Code -->
5627
</body>
5728
</html>

public/js/lazy_init.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
!function () {
2+
var t = window.driftt = window.drift = window.driftt || [];
3+
if (!t.init) {
4+
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
5+
t.invoked = !0, t.methods = ["identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on"],
6+
t.factory = function (e) {
7+
return function () {
8+
var n = Array.prototype.slice.call(arguments);
9+
return n.unshift(e), t.push(n), t;
10+
};
11+
}, t.methods.forEach(function (e) {
12+
t[e] = t.factory(e);
13+
}), t.load = function (t) {
14+
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
15+
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
16+
var i = document.getElementsByTagName("script")[0];
17+
i.parentNode.insertBefore(o, i);
18+
};
19+
}
20+
}();
21+
drift.SNIPPET_VERSION = '0.3.1';
22+
drift.load('kmcg4ky4chmh');
23+
24+
window.dataLayer = window.dataLayer || [];
25+
function gtag(){dataLayer.push(arguments);}
26+
gtag('js', new Date());
27+
28+
gtag('config', 'UA-153205738-3');

src/AppRoot.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ window.AppConfig = config;
1919
// @ts-ignore
2020
window.App = new App();
2121

22+
async function loadScriptAsync(url: string) {
23+
const script = document.createElement("script");
24+
25+
script.src = url;
26+
script.async = true;
27+
28+
document.body.appendChild(script);
29+
}
30+
31+
loadScriptAsync("https://momentjs.com/downloads/moment.min.js").then(() => {});
32+
33+
setTimeout(() => {
34+
loadScriptAsync("/js/lazy_init.js").then(() => {});
35+
}, 1000);
36+
2237
function AppRoot() {
2338
return (
2439
<div className="app">

0 commit comments

Comments
 (0)