@**
 * Copyright (c) 2013-2017, 2020 Kaj Magnus Lindberg
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *@


@(tpi: debiki.SiteTpi, loadStaffBundle: Boolean)

@* SECURITY try removing polyfill.io — it's a supply chain attack security risk.
Now soon mostly gone (feature flag) — only old browser will download a polyfill.
*@
@* [script_src_self] *@
@if(tpi.noPolyfillDotIo) {
} else if(tpi.avoidPolyfillDotIo) {
<script>{
var w = window;
if (!(w.fetch && w.Promise && [].includes && Object.assign && w.Map))
  document.write('<script src="https://cdn.polyfill.io/v2/polyfill.@{tpi.minMaxJs
        }?features=default,fetch"></sc' + 'ript>');
}</script>
} else {
<script src="https://cdn.polyfill.io/v2/polyfill.@{tpi.minMaxJs}"></script>
}

<script src="@tpi.assetUrl(s"translations/${tpi.languageCode}/i18n.${tpi.minMaxJs}")"></script>
<script src="@tpi.assetUrl(s"slim-bundle.${tpi.minMaxJs}")"></script>
@* If in the admin area or about user section, then load more scripts directly, [5WKE24]
since we need it directly, anyway. *@
@if(tpi.anyCurrentPageRole.isEmpty) {
<script src="@tpi.assetUrl(s"more-bundle.${tpi.minMaxJs}")"></script>
} else {
@* Prefetch scripts. [7PLBF20]
Safari and iOS doesn't support rel=prefetch — so the below stuff is for
everyone-except-for-those-who-use-Apple. Use rel=prefetch (not =preload), because the script is
only *perhaps* needed, and maybe not on this page but maybe on the next instead,
and, in Chrome, prefetch requests won't get terminated, when navigating to the next page
but pre*load* requests do get cancelled, see:
 https://medium.com/reloading/preload-prefetch-and-priorities-in-chrome-776165961bbf *@
<link rel="prefetch" href="@tpi.assetUrl(s"more-bundle.${tpi.minMaxJs}")" as="script">
}

@* Prefetch the editor-bundle. But it's currently needed by the staff-bundle [7PKEW24]
(for rendering posts on the moderation page) — so load it directly, if we're
loading the staff-bundle.
*@
@if(!loadStaffBundle) {
@* Or don't prefetch it. Most people only read, won't write anything — let's
save some server bandwidth and mobile phone batteries?
<link rel="prefetch" href="@tpi.assetUrl(s"editor-bundle.${tpi.minMaxJs}")" as="script">
*@
} else {
<script src="@tpi.assetUrl(s"editor-bundle.${tpi.minMaxJs}")"></script>
<script src="@tpi.assetUrl(s"staff-bundle.${tpi.minMaxJs}")"></script>
}
