Skip to content

Commit

Permalink
Defer loading of scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
holehan committed Apr 3, 2019
1 parent bb1e369 commit a24b1cc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion assets/js/matomo-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ _paq.push(['enableLinkTracking']);
var s = d.getElementsByTagName('script')[0];

g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = matomoUrl + '/piwik.js';
s.parentNode.insertBefore(g, s);
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/matomo-tracking.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- if .Site.IsServer -}}
{{ $trackingScript := resources.Get "js/matomo-tracking.js" }}
<script data-id="matomo-tracking" data-matomo-tracking-url='{{ $.Site.Params.matomo.url }}' data-matomo-tracking-id='{{ $.Site.Params.matomo.id }}' src="{{ $trackingScript.RelPermalink }}"></script>
<script data-id="matomo-tracking" data-matomo-tracking-url='{{ $.Site.Params.matomo.url }}' data-matomo-tracking-id='{{ $.Site.Params.matomo.id }}' src="{{ $trackingScript.RelPermalink }}" defer></script>
{{- else -}}
{{ $trackingScript := resources.Get "js/matomo-tracking.js" | minify | fingerprint }}
<script data-id="matomo-tracking" data-matomo-tracking-url='{{ $.Site.Params.matomo.url }}' data-matomo-tracking-id='{{ $.Site.Params.matomo.id }}' src="{{ $trackingScript.RelPermalink }}" {{ if not $.Site.Params.matomo.disableSRI }}integrity="{{ $trackingScript.Data.Integrity }}" crossorigin="anonymous"{{ end }}></script>
<script data-id="matomo-tracking" data-matomo-tracking-url='{{ $.Site.Params.matomo.url }}' data-matomo-tracking-id='{{ $.Site.Params.matomo.id }}' src="{{ $trackingScript.RelPermalink }}" {{ if not $.Site.Params.matomo.disableSRI }}integrity="{{ $trackingScript.Data.Integrity }}" crossorigin="anonymous"{{ end }} defer></script>
{{- end -}}
6 changes: 3 additions & 3 deletions layouts/shortcodes/matomo-optout.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
{{- $promisePolyfill := resources.Get "js/promise-polyfill.js" | minify | fingerprint -}}
{{- $fetchJsonp := resources.Get "js/fetch-jsonp.js" -}}
{{ $matomoOptout := resources.Get "js/matomo-optout.js" }}
<script data-id="promise-polyfill" data-promise-polyfill-url="{{ $es6Promise.RelPermalink }}" src="{{ $promisePolyfill.RelPermalink }}" {{ if not $.Site.Params.matomo.disableSRI }}integrity="{{ $promisePolyfill.Data.Integrity }}" crossorigin="anonymous"{{ end }}></script>
<script data-id="promise-polyfill" data-promise-polyfill-url="{{ $es6Promise.RelPermalink }}" src="{{ $promisePolyfill.RelPermalink }}" {{ if not $.Site.Params.matomo.disableSRI }}integrity="{{ $promisePolyfill.Data.Integrity }}" crossorigin="anonymous"{{ end }} defer></script>
{{- if .Site.IsServer -}}
{{ $matomoOptoutBundle := slice $fetchJsonp $matomoOptout | resources.Concat "js/matomo-optout.js" }}
<script data-id="matomo-optout" data-matomo-optout-url="{{ $.Site.Params.matomo.url }}" src="{{ $matomoOptoutBundle.RelPermalink }}" async></script>
<script data-id="matomo-optout" data-matomo-optout-url="{{ $.Site.Params.matomo.url }}" src="{{ $matomoOptoutBundle.RelPermalink }}" defer></script>
{{- if ne $.Site.Params.matomo.stylefromassets false -}}
{{ $matomoStyle := resources.Get "css/matomo-optout.css" }}
<link rel="stylesheet" href="{{ $matomoStyle.RelPermalink }}">
{{- end -}}
{{- else -}}
{{ $matomoOptoutBundle := slice $fetchJsonp $matomoOptout | resources.Concat "js/matomo-optout.js" | minify | fingerprint }}
<script data-id="matomo-optout" data-matomo-optout-url="{{ $.Site.Params.matomo.url }}" src="{{ $matomoOptoutBundle.RelPermalink }}" {{ if not $.Site.Params.matomo.disableSRI }}integrity="{{ $matomoOptoutBundle.Data.Integrity }}" crossorigin="anonymous"{{ end }} async></script>
<script data-id="matomo-optout" data-matomo-optout-url="{{ $.Site.Params.matomo.url }}" src="{{ $matomoOptoutBundle.RelPermalink }}" {{ if not $.Site.Params.matomo.disableSRI }}integrity="{{ $matomoOptoutBundle.Data.Integrity }}" crossorigin="anonymous"{{ end }} defer></script>
{{- if ne $.Site.Params.matomo.stylefromassets false -}}
{{ $matomoStyle := resources.Get "css/matomo-optout.css" | minify | fingerprint }}
<link rel="stylesheet" href="{{ $matomoStyle.RelPermalink }}" {{ if not $.Site.Params.matomo.disableSRI }}integrity="{{ $matomoStyle.Data.Integrity }}" crossorigin="anonymous"{{ end }}>
Expand Down
1 change: 0 additions & 1 deletion src/js/matomo-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ _paq.push(['enableLinkTracking']);
const s = d.getElementsByTagName('script')[0];

g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = `${matomoUrl}/piwik.js`;
s.parentNode.insertBefore(g, s);
Expand Down

0 comments on commit a24b1cc

Please sign in to comment.